Use CommonDictionaryStorage for class variables#1531
Merged
BCSharp merged 2 commits intoIronLanguages:masterfrom Aug 9, 2022
Merged
Use CommonDictionaryStorage for class variables#1531BCSharp merged 2 commits intoIronLanguages:masterfrom
BCSharp merged 2 commits intoIronLanguages:masterfrom
Conversation
slozier
approved these changes
Aug 9, 2022
Contributor
slozier
left a comment
There was a problem hiding this comment.
Don't kow much about this part of the codebase, but looks good to me.
| } | ||
| } | ||
|
|
||
| private MSAst.Expression SeLocalName(string name, MSAst.Expression expression) |
Contributor
There was a problem hiding this comment.
Is this a typo? SetLocalName?
Merged
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.
Part of #20.
Because it effectively changes the name lookup mechanism in a class body lambda, I was curious what performance impact this may have. The old mechanism uses
RuntimeVariableDictionaryStorage, which is backed by a fixed length array and a linear lookup. In the new code, only__class__goes there, all other variables are stored inCommonDictionaryStorage, which grows dynamically. Since the new mechanism is only required for classes created by user metaclasses, it is possible to fall back on the old mechanism if no metaclass is specified, thus maintaining the existing performance profile in most cases.Intuitively, the old mechanism should be better for small (few methods) classes, while the new approach should outperform for very large classes. But the question was where the break-even is and how much gain/loss it entails.
Here are best-case test results for classes of various sizes. N is the number of methods (with empty body). On top of that, each class has a method
greturning__self__, which adds symbolsg,__class__,__classcell__. Plus every class has the mandatory__module__. (CPython classes also have__qualname__).*CPython is for reference only, runs with GC disabled.
Standard deviation was in the order of 0.5 μs at the low end, 5 μs around N=100, and approx. 10 μs for N=500.
What it tells me that any differences between the two algorithms are negligible for any sensibly-sized class. The bulk of time is probably spend on parsing and namebinding, and the choice of storage is not a significant factor.