Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: more compact initialization of maps with dynamic content #38784
Iooking into the size of
The allowed types for this optimization were already expanded before and it seems there is room to go further.
Writing a prototype compiler CL allowing
I dont see yet see a problem with side effects if all keys are static and all values are either ONAME or statics.
Unfortunately since the values in the unicode case are pointers there are still a lot of gcwritebarrier entries that bloat the init function. There seems more room to make unicode.init smaller by optimizing the init func generation.
Interesting, thanks for pointing this out.
To summarize, in package unicode we have:
This currently gets optimized into:
The essence of this issue report is that we should further optimize it to:
and then on with the static map initialization logic.
yes there is another optimization here as you point out for getting rid of the write barriers by making the map values point to globals instead of copying pointers (we may have to rewrite the tables in unicode for that if we cant make the compiler reason about this) which I think warrants its on CL and rewrite of unicode.
The generic map optimization in addition to the write barriers here is that I think we can do (and already do for some maps) is to always transform:
Note that the current code even doesn't do the
The optimization already triggers if Var1 and Var2 are not variables but static too. My proposal is to extend the optimization to the case where the map values are are variables (for some values or all of them apart from statics).
The quick compiler CL prototype I wrote that passes ./all.bash basically allows ONAME in n.Right.Op for map init elements and sets the values array as initKindDynamic and does not set the ReadOnly flag when variables are encountered. (Its on another computer) So it is the same as initializing an array of variables as elements.
These two places need change:
I see. Thanks.
I think that should work, but I'm a little hesitant about not being able to mark the memory as Readonly. Once memory is modified by a process, it can't be freed by the OS until the process exits (or until it indicates otherwise with
I think we should try to start with just optimizing the same cases that