-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce XName lookups #19
Comments
Seems like a sensible suggestion, and with this reply I note my approval for either yourself or anyone else to begin work on a PR or issue one in the future. |
I made a PR to improve this :) You have inherited a pretty old codebase... It would benefit from some upgrades but that's a daunting task :/ |
@mamift I found a bug in this PR today. |
@mamift Small bit of feedback here. It kind of makes sense as if you develop a lib you probably want to see all members in IDE (and hide them from consumers of the lib). So just so you know, this attribute is useless right now but there is a long standing Roslyn issue about it: |
Well, someone pointed this isn't actually the issue here and the behavior was expected. |
Looking at the generated code, I'm a bit surprised that getters systematically use
XName.Get()
.When parsing files with hundreds if not thousands of repeated tags and attributes, it's a lot of unrequired calls, which are not free as they involve several thread-safe hashtables of weakreferences underneath.
I think it could be a fairly trivial code fix: simply introduce static variable for each element and attribute name, and use that instead of the
XName.Get()
expression in the code.Impact analysis of the change
One could be concerned about overall memory usage (when parsing), leaks (
XName
usesWeakRef
and releases namespaces and names once they're not referenced anymore), cost for elements that are not accessed (e.g. large xsd with only a tiny subset accessed at runtime), and initialization time.For elements, there is no impact at all.
The static ctor already creates every XName and saves it in
localElementDictionary
and sometimes incontentModel
as well.So the work to instantiate the XNames is already done anyway and they will be kept alive forever.
Attributes are created lazily on first access. They are kept alive forever though, as only full namespaces are collected when unused, not individual names.
Given all the work done anyway on elements, I don't think adding the attributes is a significant change. It should be an all-or-nothing design.
If that's really a concern, it could be done on elements only.
So in summary this change would:
The text was updated successfully, but these errors were encountered: