built-ins: use strings.Builder in glob.match()#4777
built-ins: use strings.Builder in glob.match()#4777srenatus merged 1 commit intoopen-policy-agent:mainfrom
Conversation
There was a problem hiding this comment.
Would it make a difference to use the pattern length and the number of delimiters to grow the builder to the required size upfront?
There was a problem hiding this comment.
I actually did try this, and there was not a measurable performance impact. My hypothesis is that the initial size that gets set when the pattern gets written includes enough extra space for the delimiters, so there is still only one memory allocation.
There was a problem hiding this comment.
So perhaps we'd allocate less...? But I suppose it doesn't matter.
There was a problem hiding this comment.
Yeah, I tried a number of different approaches, including just using bare strings and the + operator directly. Nothing really seemed to move the needle, so I think the real benefit here is just eliminating the constant factor Sprintf() overhead. That and not paying for string quoting by doing a direct typecast.
6a4c255 to
fff60fc
Compare
fff60fc to
0bf630c
Compare
|
Need a rubber stamp after rebasing and tweaking the benchmark so the CI won't timeout. I don't have write permissions, so feel free to merge once approved. |
Use strings.Builder to construct the ID for use in glob.match(). This offers a slight performance improvement. This also adds a benchmark to the glob.match() builtin. Signed-off-by: Charles Daniels <charles@styra.com>
0bf630c to
20ada09
Compare
Use strings.Builder to construct the ID for use in glob.match(). This
offers a slight performance improvement.
This also adds a benchmark to the glob.match() builtin.
Signed-off-by: Charles Daniels charles@styra.com
Before I made this optimization, this is what I got on the new benchmark:
And after:
Both tests were run on a 2021 14-inch Macbook Pro with an M1 Pro, 32GB of RAM, and running macOS Monterey 12.4.
I was hoping to achieve a much better speedup here, as
glob.match()is a big performance hotspot for one of my use cases. However since I already did the work to try this patch out and analyze the performance, and it is a marginal performance uplift...