cmd/compile: optimize print call sequences #48828
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Suggested
Issues that may be good for new contributors looking for work to do.
Milestone
The runtime is full of debugging calls of the form
println("a=", hex(a), "b=", hex(b))
, followed by athrow
. These are very useful when something goes wrong, but the generated code for them is very verbose. It can easily account for half of the generated code in hot runtime routines. It is placed at the end of the function, but for icache purposes, it'd be better for it to be outlined and placed far away.Given the poor share the inliner is in, I'm going to assume that we're not going to add an outliner (even one manually triggered) any time soon.
As an easier fix, I did some work a year ago on this, adding a bunch of helper print routines, like
printonestring
, which doesprintlock; printstring; printunlock
, all in a single call. And there are probably other helpful combinations I didn't add, likeprintstringhex
, which doesprintstring; printhex
. (An analysis of call ngrams would be useful.) It might also be useful to have aprintstringptr
that accepts a pointer to a string to print, instead of the string itself, for use particularly with constant strings. And maybe there are other inventive solutions that can shrink call sites further.The work I did is at josharian@9d18ed5, with preparatory commits josharian@18a0eff and josharian@ce3a481.
It no longer applies cleanly due to substantive compiler refactoring in the intervening year, but perhaps someone is interested in re-creating those patches at tip. And maybe improving them.
Because there's some existing code written to work from, this might be a good first issue for someone new to the compiler.
The text was updated successfully, but these errors were encountered: