❔ getting all methods with an attribute in an optimized way
hey all, im trying to find a way to add all methods with an attribute to dictionary. i want to be able by entering a string in a console window for debugging purposes in unity.
example of a methods im trying to find:
this is my current way of finding all methods with an attribute:
it works, but is obviously not very performant (takes multiple seconds to run this method). although i have seen other unity packages that dont seem to have any performance impact, so im sure its possible do it some other way. any help would be
10 Replies
Your current code would also examine assemblies of .Net itself
I assume you can filter these out?
If you're using reflection your perf is already going to be out the window
Aside from filtering out assemblies starting with System etc, thats about the size of it
Yeah, making sure you are only looking at relevant assemblies is probably going to make that much faster.
Also, don't do this:
Use TryAdd instead
yeah, but I dont really see any other way, but I may be missing something
forgot about that one, thanks🙂
Do you know how many assemblies you need to process?
If you want to speed this up you can use a concurrent dictionary and process each assembly in parallel.
I think so yes
Just throw a Parallel.ForEach on there and use a ConcurrentDictionary, skip assemblies you know you don't need to process and you should be good.
ez
ah cool, didnt realize it would be that simple
thanks!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.