-
Notifications
You must be signed in to change notification settings - Fork 237
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
std.format
is slow
#464
Comments
Well, std.format will always be somewhat slower than just using BTW probably a large part of 50ms in the latter example is actually printing the output. The calculation itself is probably even faster than that. |
@sbarzowski sure, that's expected. On the other hand, it would be nice to have a convenient way to concentrate the string other than using Jsonnet doesn't need to cover all the cases but I believe that string concentration is a common use-case for a data templating language. WDYT? P.S: For one of our projects, almost 80% of the time is spent on |
Rust implementation of jsonnet (https://github.com/CertainLach/jrsonnet/) implements # a.jsonnet
["%s and %s" % ['test', 'test1'] for x in std.range(0, 1000)] # b.jsonnet
local test = 'test';
local test1 = 'test1';
[test + 'and' + test1 for x in std.range(0, 1000)]
|
That's nice! This is the implementaiton, right? https://github.com/CertainLach/jrsonnet/blob/8db09e1bbe2ea8a499da56d2b972a5510a654f82/crates/jrsonnet-evaluator/src/builtin/format.rs We might want to use it as an inspiration here. |
Yep, it is |
We're heavily using string concentration via
std.format
and I realized that it dramatically hurts the performance. We had to switch using the old way'' + ''
and had a huge performance boost. Here is an example:The script above is compiled in ~5000ms whereas the following one only takes around 50ms:
I see that
std.format
is implemented in Jsonnet but I believe it might be best to implement it as a native function as the logic is complex and it affects the performance dramatically.The text was updated successfully, but these errors were encountered: