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

O(N^2) when calling PropertiesEditor .insert() N times #17

Closed
InPermutation opened this issue Oct 4, 2023 · 1 comment
Closed

O(N^2) when calling PropertiesEditor .insert() N times #17

InPermutation opened this issue Oct 4, 2023 · 1 comment

Comments

@InPermutation
Copy link
Contributor

Related to #16, my Lambda is still timing out on that ≤1000 lines x ≤400 characters file.

I have read my profiler output more carefully, and found what I think is the core performance issue: PropertiesEditor calls this.parseLines() on every .insert() call.

On the first insert, parse the first line.
On the second insert, parse the first and second lines.
On the third insert, parse the first, second, and third lines.

On the Nth insert, parse lines 0...N.

This is Shlemiel the painter's algorithm.

I would submit a PR, but I'm not yet sure what the right approach is to fixing this. (Maybe an intermediate PropertiesBuilder that only parses at the end?)

WORKAROUND: Since I am not editing a .properties file, but rather generating a brand new one, I can avoid PropertiesEditor, and instead just linearly generate my own output, using the functions in properties-file/escape.

@nbouvrette
Copy link
Contributor

@InPermutation I implemented lazy parsing which is now available in version 3.3.3

I think in a scenario where you want to do multiple inserts performance will be a lot better. Let me know if you see anything I might have missed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants