-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allocate copy of tok.Range only when it's needed
In a similar fashion as the parent commit, here instead of always copying the tok.Range for later use, we define a function to get this copied value, and thus we only allocate the copy if it's needed, otherwise don't. For the benchmark introduced earlier, the reduction in allocations and memory usage is outstanding: name old time/op new time/op delta LexConfig-12 9.05µs ± 1% 7.83µs ± 1% -13.54% (p=0.000 n=10+10) name old alloc/op new alloc/op delta LexConfig-12 7.98kB ± 0% 6.06kB ± 0% -24.07% (p=0.000 n=10+10) name old allocs/op new allocs/op delta LexConfig-12 37.0 ± 0% 7.0 ± 0% -81.08% (p=0.000 n=10+10) Benchmarks were created using: go test -benchmem -benchtime=200000x -count=10 -bench=. Signed-off-by: Leandro López (inkel) <[email protected]>
- Loading branch information
1 parent
39050fc
commit a2faa08
Showing
1 changed file
with
14 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters