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

Optimize qualified identifier creation #948

Merged
merged 3 commits into from
May 27, 2021
Merged

Optimize qualified identifier creation #948

merged 3 commits into from
May 27, 2021

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented May 26, 2021

Description

A micro-optimization:

  • Simply return the identifier, if there are no containers.
  • Avoid appending by creating the identifier-array at the lowest level of the chain (when the size is known).
  • Calculate the buffer size on the fly, and grow the string-builder buffer at once.
name                                                  old time/op    new time/op    delta
QualifiedIdentifierCreation/One_level-12              24.6ns ± 4%     2.0ns ± 1%   -91.96%  (p=0.008 n=5+5)
QualifiedIdentifierCreation/Three_levels-12            197ns ± 4%     105ns ± 7%   -46.93%  (p=0.008 n=5+5)

name                                                  old alloc/op   new alloc/op   delta
QualifiedIdentifierCreation/One_level-12               8.00B ± 0%     0.00B       -100.00%  (p=0.008 n=5+5)
QualifiedIdentifierCreation/Three_levels-12             120B ± 0%       64B ± 0%   -46.67%  (p=0.008 n=5+5)

name                                                  old allocs/op  new allocs/op  delta
QualifiedIdentifierCreation/One_level-12                1.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
QualifiedIdentifierCreation/Three_levels-12             4.00 ± 0%      2.00 ± 0%   -50.00%  (p=0.008 n=5+5)


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@SupunS SupunS self-assigned this May 26, 2021
@SupunS SupunS force-pushed the supun/perf-opti-3 branch 2 times, most recently from 4b28fde to ccc8742 Compare May 26, 2021 15:55
@SupunS SupunS marked this pull request as ready for review May 26, 2021 15:56
@SupunS SupunS requested a review from turbolent as a code owner May 26, 2021 15:56
runtime/interpreter/interpreter.go Outdated Show resolved Hide resolved
runtime/sema/type.go Show resolved Hide resolved
runtime/sema/type.go Outdated Show resolved Hide resolved
runtime/sema/type_test.go Show resolved Hide resolved
@turbolent
Copy link
Member

This is a great optimization! This code is called often, so optimizing it makes a lot of sense 👍

@codecov-commenter
Copy link

codecov-commenter commented May 27, 2021

Codecov Report

Merging #948 (1222de9) into master (a0332c6) will increase coverage by 0.03%.
The diff coverage is 92.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #948      +/-   ##
==========================================
+ Coverage   74.05%   74.08%   +0.03%     
==========================================
  Files         269      269              
  Lines       33074    33089      +15     
==========================================
+ Hits        24492    24515      +23     
+ Misses       7453     7445       -8     
  Partials     1129     1129              
Flag Coverage Δ
unittests 74.08% <92.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
runtime/sema/type.go 87.68% <92.00%> (+0.40%) ⬆️
runtime/interpreter/interpreter.go 90.05% <0.00%> (-0.09%) ⬇️
runtime/runtime_storage.go 87.87% <0.00%> (+1.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0332c6...1222de9. Read the comment docs.

@SupunS SupunS mentioned this pull request May 27, 2021
6 tasks
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@SupunS SupunS merged commit 36edebd into master May 27, 2021
@SupunS SupunS deleted the supun/perf-opti-3 branch June 1, 2021 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants