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

Use objectpath.Encoder to amortize the cost of encoding the paths of multiple objects #140

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

yuxincs
Copy link
Contributor

@yuxincs yuxincs commented Nov 28, 2023

We are using objectpath.For very heavily in our inference engine to construct package-independent object identifiers. However, each invocation comes with a cost of initializations (construction and traversal of the scope tree).

Since x/tools v0.9.0 (we are currently on v0.11.0), there is an objectpath.Encoder that "amortizes the cost of encoding the paths of multiple objects". This PR uses the encoder for better performance. There aren't/shouldn't be any functionality changes.

A quick profile showing the timing before & after this PR for accumulation.run function (the entrypoint function for our inference engine):

before:

31.43s 22.49% |   go.uber.org/nilaway/accumulation.run
15.69s 49.92% |   go.uber.org/nilaway/inference.(*Engine).ObservePackage
8.11s 25.80%  |   go.uber.org/nilaway/inference.(*Engine).ObserveUpstream
3.33s 10.59%  |   go.uber.org/nilaway/inference.(*InferredMap).Export
...

after:

18.34s 14.63% |   go.uber.org/nilaway/accumulation.run
8.55s 46.62%  |   go.uber.org/nilaway/inference.(*Engine).ObserveUpstream
3.65s 19.90%  |   go.uber.org/nilaway/inference.(*InferredMap).Export
2.50s 13.63%  |   go.uber.org/nilaway/inference.(*Engine).ObservePackage
...

@yuxincs yuxincs requested review from lazaroclapp and sonalmahajan15 and removed request for lazaroclapp November 28, 2023 15:12
Copy link
Contributor

@sonalmahajan15 sonalmahajan15 left a comment

Choose a reason for hiding this comment

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

Wow, this is quite promising! Let's confirm the benefits via performance evaluation internally, as well as, a sanity check for ensuring there are no functionality changes, i.e., the errors reported for a given set of test targets remain the same.

@yuxincs yuxincs force-pushed the yuxincs/use-objectpath-encoder branch from b865a48 to 336d11c Compare November 29, 2023 18:42
Copy link

codecov bot commented Nov 29, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f9441c8) 88.97% compared to head (336d11c) 88.97%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #140   +/-   ##
=======================================
  Coverage   88.97%   88.97%           
=======================================
  Files          54       54           
  Lines        8253     8254    +1     
=======================================
+ Hits         7343     7344    +1     
  Misses        753      753           
  Partials      157      157           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yuxincs yuxincs merged commit 0ef3071 into main Nov 30, 2023
4 checks passed
@yuxincs yuxincs deleted the yuxincs/use-objectpath-encoder branch November 30, 2023 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants