Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache type refs during import #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

gluck
Copy link
Contributor

@gluck gluck commented Jun 1, 2015

  • importing many types/methods would result in millions of duplicate
    TypeRef objects, this basic caching saves lots of memory in that use case.
  • one issue with it has to do with Cecil not filling up GenericParameters
    for all types (hence the workaround). Was seen during Dapper or Bcl UTs.

I guess this change can be debated, but as it bring a large perf impact for ILRepack (~20%), I kind'o need it 馃槃
Other ways to tackle it would be:

  • to add an option for the metadataimporter to cache (or not)
  • make the metadataimporter public & overrideable, so that one (ILRepack) could add a caching layer on top of it

If those sound more appropriate for Cecil, I can modify this PR accordingly (though IMO, all import use cases would benefit from this cache).

MethodRef could/should be cached similarly, but the impact is lesser than TypeRefs.

- importing many types/methods would result in millions of duplicate
 TypeRef objects, this basic caching saves lots of memory in that use case.
- one issue with it has to do with Cecil not filling up GenericParameters
 for all types (hence the workaround). Was seen during Dapper or Bcl UTs.
var key = TypeRefKey.From (type);
if (cache.TryGetValue (key, out reference))
{
// Cecil only fills TypeRef GenericParameters if used ( bug ?)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw this should be properly fixed IMO, so I don't expect this to be merged as-is 馃槃

I didn't quite find where to make the proper fix though.
AFAICT Cecil creates trivial GenericParameter's only upon use during assembly read.

@jbevain
Copy link
Owner

jbevain commented Jun 1, 2015

It's now easy for you to override the MetadataImporter with your own. See ReaderParameters.MetadataImporterProvider

@gluck
Copy link
Contributor Author

gluck commented Jun 1, 2015

Oh missed that, thanks.
Though right now (correct me if I'm wrong), if I want to add this TypeRef cache on top of the regular MetadataImporter, I need to re-write (copy/paste) it entirely, and I'll probably miss some internal-only bits (e.g. the last merged PR from me requires internal visibility).

@jbevain
Copy link
Owner

jbevain commented Jun 1, 2015

I'm pretty sure you can extend MetadataImporter and override ImportReference to call base.ImportReference only if not cached.

@gluck
Copy link
Contributor Author

gluck commented Jun 1, 2015

That would work if the MetadataImporter called ImportReferences in its various Import methods, but it doesn't, it calls ImportType instead (private).

@gluck
Copy link
Contributor Author

gluck commented Jun 1, 2015

(I can make a PR to change only that, and will be able to manage the caching on my side then)

@jbevain
Copy link
Owner

jbevain commented Jun 1, 2015

Right. Let me think about it some more and I'll get back to you.

@SimonCropp
Copy link
Contributor

@jbevain is this still a viable change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants