Implement embedded TypedData objects #7440
Merged
peterzhu2118 merged 2 commits intoruby:masterfrom Nov 7, 2023
Merged
Conversation
da31399 to
6e65bee
Compare
Contributor
|
Hum, it just hit me: what is the impact on compaction?
But if we embed the struct, and the extension pass pointers to members of the struct to various C APIs, moving the struct might break, right? |
Member
Author
|
Since this is opt-in and as long as we don't store the pointer anywhere, then it should be safe for compaction (assuming that the object is also on the stack using |
6e65bee to
54915d0
Compare
Member
Author
|
I added a bunch of |
54915d0 to
c3f5db7
Compare
This commit adds a new flag RUBY_TYPED_EMBEDDABLE that allows the data of a TypedData object to be embedded after the object itself. This will improve cache locality and allow us to save the 8 byte data pointer. Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
c3f5db7 to
88034f0
Compare
Contributor
|
88034f0 to
e335dfa
Compare
This drops the total size of a Time object from 86 bytes to 80 bytes.
Running the benchmark benchmark/time_now.yml, this commit improves
performance of Time.now by about 30%:
```
Time.now
Branch: 13159405.4 i/s
Master: 10036908.7 i/s - 1.31x slower
Time.now(in: "+09:00")
Branch: 2712172.6 i/s
Master: 2138637.9 i/s - 1.27x slower
```
It also decreases memory usage by about 20%:
```
ary = 10_000_000.times.map { Time.now }
puts `ps -o rss= -p #{$$}`
```
Branch: 961792
Master: 1196544
Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
e335dfa to
1331e72
Compare
Contributor
|
Seems like we introduced an issue for some gems: I'll try to figure this out. |
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 PR adds a new flag RUBY_TYPED_EMBEDDABLE that allows the data of a TypedData object to be embedded after the object itself. This will improve cache locality and allow us to save the 8 byte data pointer.
This PR also implements this feature on Time objects, which drops the total size of a Time object from 86 bytes to 80 bytes.
This PR is based on top of #7438.
Co-Authored-By: @byroot