google / google/go-jsonnet

`std.format` is slow

Open
#464 5 comments 0 reactions 0 assignees View on GitHub
performance stdlib
Dominant language
Go
Stars
1.8k
Forks
263
PR merge metrics
No merged PRs in 30d

Description

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:

```
["%s and %s" % ['test', 'test1'] for x in std.range(0, 1000)]
```

The script above is compiled in ~5000ms whereas the following one only takes around 50ms:

```
local test = 'test';
local test1 = 'test1';

[test + 'and' + test1 for x in std.range(0, 1000)]
```

I see that `std.format` is [implemented in Jsonnet](https://github.com/google/jsonnet/blob/master/stdlib/std.jsonnet#L307) 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.