Conversation
ctk-1998
requested review from
BoyaoWang430,
lxq015,
newborn22,
wangpc-pp and
wenchangping
August 24, 2026 01:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue(s) & Descriptions
Original pr: https://atomgit.com/openeuler/golang/pull/77, authored by rfwang07.
Port the ARM64-only optimization that folds []byte(string([]byte)) into a single runtime.makeslicecopy call to riscv64.
The pattern normally lowers into two runtime calls, each allocating and copying the data:
The new pass runs after lowering and replaces the pair with a single runtime.makeslicecopy call, halving both heap allocations and copies:
The rewrite is gated behind -bytesstringbytesopt (off by default) and only fires when the conversion escapes to the heap (tmpBuf == nil), so small conversions that use a stack temporary are left unchanged.
The port maps the ARM64-specific SSA ops to their riscv64 equivalents (OpARM64CALLstatic -> OpRISCV64CALLstatic, OpARM64MOVDconst -> OpRISCV64MOVDconst, OpARM64MOVDaddr -> OpRISCV64MOVaddr) and adapts the codegen assertion to the riscv64 JAL call mnemonic.
Tests
Benchmarks on sg2044:
Why does the benchmark regress at n=32?
Measurements confirm that allocs/op drops from 2 to 1 and B/op is roughly halved — the optimization genuinely saves work (one allocation and one copy); it simply doesn't translate into faster wall-clock time. The likely cause is a code-layout effect: enabling the optimization changes the machine code size of the hot function (or hot loop), so the critical call/branch instructions in the loop land on different 64-byte cache line boundaries, altering CPU front-end instruction fetch efficiency.
The absolute time at n=32 is only 158 ns. At that scale, the "one mallocgc + one memmove" saved by the optimization amounts to only a few tens of nanoseconds, while the alignment/fetch effect caused by the change in code size is also on the order of tens of nanoseconds. The two are comparable, so the net direction is essentially random: n=8 comes out slightly faster (−16.68%) while n=32 comes out slightly slower (+16.51%). From n≥128 onward, allocation and copying dominate the runtime, drowning out the layout noise, and the optimization consistently shows ~−49%.
Checklist