Shared empty iv_tbl of module#6216
Merged
Merged
Conversation
## Implementation Summary * Only keys and only values of hash table are contiguous to eliminate structure padding. * Change upper limit of `iv_tbl` size to `UINT16_MAX` (it seems to be acceptable in mruby because the total number of classes/modules immediately after starting Redmine is 20,000 or less). * `iv_tbl*` point hash buckets directly. ## Benchmark Summary Only the results of typical situations on 64-bit Word-boxing are present here. For more detailed information, including consideration, see below report (although most of the body is written in Japanese). * https://shuujii.github.io/mruby-iv-benchmark ### Memory Usage Lower value is better. | iv_tbl Size | Baseline | New | Factor | |------------:|---------------:|---------------:|-----------:| | 4 | 88B | 52B | 0.59091x | | 30 | 536B | 388B | 0.72388x | | 100 | 2072B | 1540B | 0.74324x | | 200 | 4120B | 3076B | 0.74660x | Although not mentioned in the above report, the memory usage of `mrbtest` (full-core gembox) is as follows in the result by Valgrind. * Baseline: 108,086 allocs, 16,313,122 bytes allocated * New: 94,273 allocs, 15,875,214 bytes allocated ### Performance Higher value is better. #### `mrb_obj_iv_set` | iv_tbl Size | Baseline | New | Factor | |------------:|---------------:|---------------:|-----------:| | 4 | 88.63003M i/s | 92.60611M i/s | 1.04486x | | 30 | 32.97066M i/s | 25.25095M i/s | 0.76586x | | 100 | 16.33224M i/s | 22.74998M i/s | 1.39295x | | 200 | 5.64484M i/s | 6.79949M i/s | 1.20455x | #### `mrb_obj_iv_get` | iv_tbl Size | Baseline | New | Factor | |------------:|---------------:|---------------:|-----------:| | 4 | 217.58391M i/s | 237.59912M i/s | 1.09199x | | 30 | 139.56195M i/s | 160.49470M i/s | 1.14999x | | 100 | 143.09716M i/s | 190.95047M i/s | 1.33441x | | 200 | 89.75291M i/s | 134.78717M i/s | 1.50176x | ### Binary Size Lower value is better. | File | Baseline | New | Factor | |:------------|---------------:|---------------:|-----------:| | mruby | 697,520B | 697,520B | 1.00000x | | libmruby.a | 1,046,570B | 1,046,682B | 0.99989x | ## Note The address in `struct RObject::iv` may change after initialization because `iv_tbl*` points directly to hash buckets. Therefore, the address cannot be copied and shared when include/prepend. So, when sharing `iv_tbl`, refer to it via the sharing source class. As a result, the following bug have also been fixed. * [An `iv_tbl` is not shared when a class includes or prepends an empty module](https://gist.github.com/shuujii/0ac23fa24b0c55b2c602b534d81e4a95)
This will be a partial merge of mruby#5317 with the following changes. - Remove `iclass->iv_c` since `iclass->iv_c` is equivalent to `iclass->c`. - `class_iv_ptr()` returns a single pointer instead of a double pointer.
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.
This will be a partial merge of #5317 with the following changes.
iclass->iv_csinceiclass->iv_cis equivalent toiclass->c.class_iv_ptr()returns a single pointer instead of a double pointer.