Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/cgo: avoid calls to cgoCheckPointer when debug.cgocheck=0 #28454
https://golang.org/cl/142884 changes cgo generated code to:
I propose, instead of checking
We could file a separate issue for making cgocheck=1 faster, but as it stands, it has a pretty substantial cost. I measured ~50ns per checked argument in the trivial case (
In these environments, it makes much more sense to run with cgocheck=2 during development, but to use cgocheck=0 in production.
Just to clarify, I'm not excited about it either and would rather see a check that has close to zero cost.
The other things I thought that might be possible are:
However, all of these seem to need significantly more effort than this change, but also are complimentary to the external check.
I did a bunch of experiments on https://github.com/egonelbre/exp/blob/master/bench/call/cgo.go#L50.
PS: note, my machine is somewhat noisy, so take the results with a grain of salt.
Baseline vs disabling code generation:
Baseline vs outer if:
Baseline vs combined: