Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw row access for increased performance. #596

Open
Splizard opened this issue Mar 17, 2020 · 1 comment
Open

Raw row access for increased performance. #596

Splizard opened this issue Mar 17, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@Splizard
Copy link

Splizard commented Mar 17, 2020

At the moment, any sort of filter operation where rows are (iterated in any order) and then deleted is very slow.
This is mainly due to the fact that the entire Row slice is copied for each RemoveRow operation.

xlsx.SheetData.Row = append(xlsx.SheetData.Row[:rowIdx],
	xlsx.SheetData.Row[rowIdx+1:]...)[:len(xlsx.SheetData.Row)-1]

Modifying the Row slice directly (ie filtering in-place) is fast. However there is no public interface to access this slice, it is accessed by the private method workSheetReader.

Could workSheetReader be made public? I realize the R value needs to be updated to reflect the row number and this could be confusing to users of the API but this could be documented and I think the performance gains are worth it.

Alternatively could a 'Rows' struct be created with methods for slicing, appending 'Row' objects?
Then you can check that the rows have proper R values.

Here is an example interface, (the types can just be a struct).

type Row interface {
    SetValue(column int, value interface{}) error
    SetColumns([]string) error
    Columns() []string
}

type Rows interface {
    Replace(int, Row)
    Index(int) Row
    Append(Row) Rows
    AppendRows(Rows) Rows
    Slice(i, j int) Rows
}

I can knock something together and create a pull request if you like.

@xuri
Copy link
Member

xuri commented Mar 17, 2020

Hi @Splizard, thanks for your issue. I propose deleting a row by filter in-place in the RemoveRow function and hold workSheetReader unexported.

@xuri xuri added the enhancement New feature or request label Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants