Use array instead of linked list for rbs location's child #1786
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.
This PR reduces memory usage by replacing the linked list with an array for
RBS::Location
.RBS::Location
has child locations. They are implemented as two linked lists, but this is not memory efficient.Therefore this PR replaces the linked lists with an array.
This PR is the first part of memory usage improvement for
RBS::Location
. I'll try reducing memory with another approach. See this document for more information. https://hackmd.io/QNkMU6roTqSn_iXb2ENhsAData structure
This is the previous data structure.
Comments are byte sizes (on my 64bits local machine).
By this change, these structs are changed to the following:
The byte size is changed like following:
rbs_loc
does not have children:rbs_loc
has children:Benchmarking
Memory Usage
With
bundle exec ruby benchmark/memory_new_env.rb
andbenchmark/memory_new_rails_env.rb
before
after
The retained memory is reduced 3% (349kb) on the core env and 4% (2MB) on the Rails env.
Execution time
With
bundle exec ruby benchmark/benchmark_new_env.rb
.before
after
It is 1.04x faster on the core env and 1.05x faster on the Rails env.