Skip to content
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

Increase performance and reduce allocations in hclsyntax.LexConfig #490

Merged
merged 3 commits into from Feb 16, 2022

Commits on Feb 16, 2022

  1. Copy the full SHA
    7beec5f View commit details
    Browse the repository at this point in the history
  2. hclsyntax: Copy only tok.Range instead of whole object

    Doing this reduces the memory used in ~11%, as the following benchstat
    comparison shows:
    
        name          old time/op    new time/op    delta
        LexConfig-12    9.27µs ± 0%    9.03µs ± 1%   -2.55%  (p=0.000 n=9+10)
    
        name          old alloc/op   new alloc/op   delta
        LexConfig-12    8.94kB ± 0%    7.98kB ± 0%  -10.74%  (p=0.000 n=10+10)
    
        name          old allocs/op  new allocs/op  delta
        LexConfig-12      37.0 ± 0%      37.0 ± 0%     ~     (all equal)
    
    Benchmarks were created using:
    
        go test -benchmem -benchtime=200000x -count=10 -bench=.
    inkel authored and apparentlymart committed Feb 16, 2022
    Copy the full SHA
    6fe2e71 View commit details
    Browse the repository at this point in the history
  3. hclsyntax: 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=.
    inkel authored and apparentlymart committed Feb 16, 2022
    Copy the full SHA
    3d38be3 View commit details
    Browse the repository at this point in the history