Performance Improvement: Replacing get_interned_obj_prop with get_obj_prop#214
Draft
Performance Improvement: Replacing get_interned_obj_prop with get_obj_prop#214
get_interned_obj_prop with get_obj_prop#214Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Benchmarking revealed that using
get_obj_propinstead ofget_interned_obj_propfor property access in generated code results in a ~19% reduction in instruction count across all tested scenarios.Background
The
shopify_function_macrogenerates accessor methods for struct fields when processing GraphQL queries. Previously, these accessors used interned string lookups (get_interned_obj_prop) with the assumption that caching string IDs would improve performance for repeated property accesses.Previous Implementation
New Implementation
Benchmark Results
Tests were run using the
integration_testscrate withfunction-runnerto measure instruction counts.Test Cases
target_atarget_binput.id())target_cartquantityon eachInstruction Counts
get_interned_obj_propget_obj_propMemory Usage
Memory usage remained constant at 1,152 bytes across all tests for both implementations.
Analysis
The interned string approach was expected to provide benefits when the same property name is accessed multiple times (e.g., in loops). However, benchmarking showed the opposite:
The overhead of interned string caching exceeds its benefits in all tested scenarios.
The overhead comes from:
CachedInternedStringIdstatic.load()to retrieve the interned IDget_interned_obj_propprovider call itselfEven with 100 iterations accessing the same property (
quantity), the direct string-basedget_obj_propapproach is ~19% faster.Conclusion
The simpler
get_obj_propimplementation:CachedInternedStringIdThis change has been applied to the
shopify_function_macrocrate.Reproducing the Benchmark
Run the integration tests with output:
cargo test -p integration_tests -- --nocaptureThe test output includes instruction counts and memory usage for each test case.