-
Notifications
You must be signed in to change notification settings - Fork 1.5k
parser: string template and unescaping nitpicks #8135
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
Conversation
|
I'm on battery right now, will check the benchmarks when back at my plug. |
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| StringTerm("/𝄞"), | ||
| ), | ||
| }, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had believed for a moment that we could use strconv.Unquote, but these are some characters where this differs from the JSON unescaping. So, added a case just to be explicit.
|
|
Some diffs there are a bit mysterious, but I think it's overall going into the right direction. 🔍 |
Hmm what is this? Now it went the other way. Above, the diff was -75% 😮 |
|
OK the bottom line is: allocs go down for string-heavy parsing, as expected: |
This should avoid a couple of allocations. Signed-off-by: Stephan Renatus <[email protected]>
For string templates, the snippets to iterate over are expected to be small, so this shouldn't be much extra work. At any rate, avoiding to go through `json.Unmarshal` is probably a good idea if possible. Signed-off-by: Stephan Renatus <[email protected]>
333ebbb to
52df2d1
Compare
johanfylling
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Haven't found the benchmark where this changes things. But it looks worthwhile, avoiding a bunch of allocs.