icall: optimize - #97
Conversation
There was a problem hiding this comment.
Review: icall i_x optimization
No blocking issues found. This applies two well-scoped micro-optimizations to func i_x identically across all 9 non-regabi files (the cmd/icall_gen/_data/icall.go template plus the 8 generated copies), and the template/generator stay in sync so regeneration will not revert the change.
What changed
cmd/icall_gen/_data/icall.go:88-89,103-105— preallocatein := make([]reflect.Value, inCount)and index-assign instead of[]reflect.Value{receiver}+append. This replaces the 1→2→4… slice regrowth with a single correctly-sized allocation.inCount = NumIn()is always ≥ 1, soin[0]and the1..inCount-1loop cover every slot exactly.cmd/icall_gen/_data/icall.go:119— replace the byte-by-byte out-copy loop withcopy(unsafe.Slice(...), unsafe.Slice(...)). Both slices are lengthinfo.OutSize, socopymoves exactlyOutSizebytes (memmove-backed, at least as fast); this block only runs whenOutTyp.NumField() > 0.
Verified
- Correctness: both changes are behaviorally equivalent to the prior code.
- Memory safety:
po := unsafe.Pointer(out.UnsafeAddr())is the correct same-expression pattern;pois a realunsafe.Pointerused at thecopy, keepingoutlive. Source read stays within bounds (OutSize ≤ OutTyp.Size()) and destination arithmetic (add(p, info.InSize)+OutSize) is unchanged. - Consistency: the change is byte-identical across all 9 files at the same lines; the regabi template is correctly left untouched (different code path).
Non-blocking nits (optional)
_data/icall.go:119— the single-linecopynests twounsafe.Slicecalls plusadd(...); extractingdst := add(p, info.InSize, "")would improve readability.- Out of scope, noted for future follow-up: the per-call
buf := make([]byte, sz)(:96) and per-fieldinArgs.Field(i-1)remain the dominant allocations on the argument side.
Review:
|
No description provided.