[forceinline] add Kunpeng forceinline optimization - #161
Conversation
| WrapGlobalMapDbg int `help:"debug trace output for global map init wrapping"` | ||
| WrapGlobalMapCtl int `help:"global map init wrap control (0 => default, 1 => off, 2 => stress mode, no size cutoff)"` | ||
| ZeroCopy int `help:"enable zero-copy string->[]byte conversions" concurrent:"ok"` | ||
| ForceInline int `help:"enable force inline"` |
There was a problem hiding this comment.
Add concurrent:"ok" here. Without this tag, the compiler will set ConcurrentOk=false and force the backend worker count to 1, which will significantly increase build time.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| case 1: | ||
| // Add default force inline function list. | ||
| // You may need update this list when you update the go version. | ||
| forceInlineMap = map[string]struct{}{ |
There was a problem hiding this comment.
Given that Go versions are subject to upgrades, the function list here may require updates accordingly; a means of recording this pending action is needed.
There was a problem hiding this comment.
Thank you for your suggestion. I've added assertion-based tests (TestScript/forceinline) that verify every function in the force-inline list is actually force-inlined. This acts as a safety net: if we upgrade the Go version but forget to adapt the list, the test will fail and all.bash will catch it.
ctk-1998
left a comment
There was a problem hiding this comment.
Do we have any performance data?
|
|
||
| "runtime.mallocgcSmallScanNoHeader": {}, | ||
|
|
||
| "runtime.mallocgc": {}, |
There was a problem hiding this comment.
IIUC, runtime.mallocgc has a high cost. If we force it to be inlined by default, it would significantly increase pressure of i-cache, resulting in performance degradation rather than improvement. Has this function been tested independently?
There was a problem hiding this comment.
Yes, the default forceinline set (which includes mallocgc) improves performance by 1.56% over the baseline, with 5 statistically significant results (p=0.002). Excluding mallocgc from the forceinline set leads to a 0.46% regression. Benchmark results have also been added to the PR description.
[port] forceinline: add Kunpeng forceinline optimization for runtime hot paths
Port of https://gitcode.com/openeuler/golang/pull/66 to the ZTE RISC-V toolchain.
Summary
Adds a Kunpeng-targeted forceinline pass that forcibly inlines selected hot functions in
runtime.mallocgcand related allocation/GC paths, bypassing the normal inline cost budget. The feature is fully gated by a new compiler debug flag and is off by default, so existing builds are unaffected.Two new
-dflags are introduced:-d=forceinline=1— enable the default force-inline function list-d=forceinlinelog— print force-inline decision logs (for diagnostics)Usage
Verification
1. Functional / correctness
Ran the bundled script test to verify the gating semantics:
Case Result
-d=forceinline=1 default list takes effect ✅
-d=forceinline=0 disables the feature ✅
-d=forceinline=2 rejected with -forceinline does not support setting to 2 ✅
-l has higher priority than forceinline ✅
Binary equivalence (two identical builds produce identical binaries) ✅
2. Benchmark
The default forceinline set (which includes mallocgc) shows a -1.56% improvement relative to the baseline, with 5 statistically significant items (p=0.002). Excluding mallocgc from the forceinline set results in a +0.46% regression relative to the baseline.
Notes
The default force-inline function list was adapted for the Go 1.26.5 runtime layout (runtime.scanobject → runtime.scanObject; removed writeHeapBits.*, mallocgc1/2, deductAssistCredit2, which no longer exist in this version). See the in-code comment: "You may need update this list when you update the go version."