-
Notifications
You must be signed in to change notification settings - Fork 440
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
Nontrivial string processing can get very slow #222
Comments
I wonder whether most of the problem is that std.join is currently not implemented with O(1) allocations and O(n) work like it should be. |
That could probably be improved, but in my example above, the big speed difference came from replacing the fancy |
You can use divide and conquer to build your string in O(n log n) instead of O(n**2) with:
|
A better solution would be that internally, jsonnet should use pure functional balanced binary trees to represent strings as well as arrays and dicts. Then, all simple operations would be O(log n). Actually, independently from the above, we could also have special O(n) constructors based on monadic iterators: functions that when applied to an accumulator, return a triplet [isDone, nextValue, nextAccumulator]. Then performance would have the correct asymptotic behavior. |
I think it's mostly caused the back-and-forth between lists of characters and strings.
For example, I have a function that takes a list of strings and "camelCases" the list, so that
["foo", "bar", "baz"]
turns into "fooBarBaz". Using that function on lots of strings in my larger evaluation makes the whole thing take about 40s. Replacing it with a simplefunction (x) std.join("-", x)
for hyphenated names reduces total evaluation time to 10s, keeping other things equal.The camelcase code is as follows:
Not the most beautiful thing ever, but it works as intended, other than being super slow.
The text was updated successfully, but these errors were encountered: