-
Notifications
You must be signed in to change notification settings - Fork 59
[generator] Remove global state around code generation #444
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Overall, I don't think that this is a good idea/is (currently) doomed to fail, for one reason:
For all binding projects except So long as See also:
I can imagine only two ways to make this work in principal:
One idea tossed around for (2) was to have each thread separately load every assembly, e.g. instead of loading (1) is probably too much work, and (2) is only an idea, with no confirmation that it could work. |
Fair enough, I think I can make it thread-safe with some other cleanup I want to do. I want to have a I will look further into that. |
For this PR, I would like to keep all the work around removing shared state, and I have reverted the bit about generating types in parallel. We can possibly revisit that in a future PR. |
using (var sw = gen_info.OpenStream (opt.GetFileName ("Java.Interop.__TypeRegistrations"))) { | ||
|
||
Dictionary<string, List<KeyValuePair<string, string>>> mapping = new Dictionary<string, List<KeyValuePair<string, string>>> (); | ||
foreach (KeyValuePair<string, string> reg in gen_info.TypeRegistrations.OrderBy (p => p.Key, StringComparer.OrdinalIgnoreCase)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relatedly: the .OrderBy()
is particularly useful now; see also: https://github.com/xamarin/java.interop/pull/442/files#r303698944
A batch of commits that make generating the type
.cs
files thread-safe, and enables writing them in parallel. On my 6 core machine, this reduces time taken generating the types inMono.Android.dll
from ~31s to ~5.2s.