-
Notifications
You must be signed in to change notification settings - Fork 18k
x/text/unicode/runenames: compiling tables.go is slow due to long string concatenation #18078
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
Comments
/cc @mdempsky |
Looks like O(n^2) in evconst. I'll take a quick peek. |
The old gc parser turned The logic in evconst to coalesce OADDSTRs expects a flat list, not a deep tree, and ends up building the giant string one piece at a time instead of all at once, thus O(n^2). I suspect the right fix is probably to change noder.go, to mimic the old parser's behavior, at least for now; there are probably other places where the compiler assumes flattened bin op trees. Leaving for @mdempsky after all. |
Can you clarify what makes you say this? As far as I can tell, we used to parse |
Is anyone able to confirm that tip is worse than Go 1.7.3 at compiling x/text/unicode/runenames? Some quick benchmarking on my workstation with /bin/time suggests that tip is using less memory than 1.7.3 ("maxresident" around 4.4M vs 8.6M, and 1.1M minor pagefaults instead of 2.1M). |
On my Mac desktop (which has enough RAM to build this), yeah, I see Go 1.8 slightly better. Both numbers are after running once, then deleting the runenames.a file, then running again:
|
Oh, tables.go is a new file, only a couple weeks old. It's not a compiler regression. I think we could efficiently handle the special case of concatenated string literals at least. I'll take a look. If it's non-intrusive enough, maybe we can still do it for 1.8. But otherwise, we should probably look for a workaround in x/text/unicode/runenames instead. One possibility might be to use explicit parentheses to balance the concatenations. E.g., |
I experimented with changing x/text/internal/gen/code.go's WriteString method to use parentheses to force balanced concatenations, and x/text/unicode/runenames now builds with 52k "maxresident" and 14k minor pagefaults. |
Either way. (fix compiler or fix generator) As long as things aren't red. |
Huh. I would have sworn... I say we fix the generator for 1.8 and the compiler for 1.9. I looked again at the compiler fix and while it wouldn't be hard to hack something in, there's not a clean, simple, clearly correct place/way to do it. |
Related: #16394 |
Retargeting this issue at fixing x/text for 1.8. We can use #16394 to track fixing cmd/compile for 1.9. |
We also need to fix x/text anyway, because fixing cmd/compile at tip won't help x/text build for older Go releases. |
CL https://golang.org/cl/33598 mentions this issue. |
The subrepos need to be building before we do a release.
The x/text/unicode/runenames is currently failing on the trybots due to lack of memory, even after I doubled their container memory limits from 2GB to 4GB.
Compiling x/text/unicode/runenames is taking over 4GB of ram.
Actually, my development VM (also 4GB, no swap) also fails to compile this. I do not want to make my VM larger.
Can we make the auto-generated tables nicer to the compiler, or can the compiler be smarter about not going pathological on this input and not optimize something it's trying to optimize?
/cc @nigeltao @randall77
The text was updated successfully, but these errors were encountered: