Provide concrete-only traversal for Class#subclasses#8480
Merged
headius merged 2 commits intojruby:masterfrom Dec 4, 2024
Merged
Provide concrete-only traversal for Class#subclasses#8480headius merged 2 commits intojruby:masterfrom
headius merged 2 commits intojruby:masterfrom
Conversation
For classes with many singletons, the Class#subclasses walk will
cost significantly more than is warranted for the few concrete
classes it will return. This can be eliminated by tracking whether
each entry is concrete and adding a separate traversal link to the
next concrete class in the chain.
Performance of such a case is significantly better:
Before:
```
1 thread Numeric.subclasses
1.315k (± 4.6%) i/s - 6.612k in 5.040800s
1 thread Object.subclasses
56.282 (± 3.6%) i/s - 285.000 in 5.074688s
1 thread Custom.subclasses with 1000 singletons
5.588 (± 0.0%) i/s - 28.000 in 5.021174s
```
After:
```
1 thread Numeric.subclasses
2.402k (± 3.4%) i/s - 11.990k in 4.998757s
1 thread Object.subclasses
189.977 (± 6.8%) i/s - 954.000 in 5.068134s
1 thread Custom.subclasses with many singletons
3.439k (± 1.0%) i/s - 17.334k in 5.040639s
```
c1e9844 to
470dd56
Compare
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.
For classes with many singletons, the Class#subclasses walk will cost significantly more than is warranted for the few concrete classes it will return. This can be eliminated by tracking whether each entry is concrete and adding a separate traversal link to the next concrete class in the chain.
Performance of such a case is significantly better:
Before:
After: