Skip to content

Poor image insertion performance in far rows #706

@a1tus

Description

@a1tus

Hello.

I've used your lib to write a simple util that takes paths to images from one column, creates a thumbnail and pastes it to another column via AddPictureFromBytes.

Everything worked fine but I've noticed that for files with thousands of rows every next insertion took exponentially longer time.
For example, files with from 0 to 1k of rows are processed nearly instantly, 5-10k takes several minutes, >10k can take up to an hour.

I've found a problem, made a fork and used it so now it takes linear time to insert images anywhere.
Please consider if it can be useful for someone else.

The fix is pretty simple (in fact I've just deleted some of unused code): a1tus@2bbe157

positionObjectPixels calculates yAbs via cycle from 0 to the current row and summing getRowHeight results.
getRowHeight by itself have an identical cycle inside (not sure why it's written like that instead of accessing SheetData.row[i] directly). So that's where we get these exponential time grow.

But the most fun fact (and also why the fix is so simple) is that xAbs/yAbs results of positionObjectPixels is not used anywhere! If you think that it's still needed then we can add bool param to skip these calculations for some particular cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions