4 ms·
The post is about the cost of calling SetFinalizer. Looking at https://github.com/golang/go/blob/master/src/runtime/mfinal.go#L388 https://github.com/golang/go/
by ankurdhama 3y ago
The post is about the cost of calling SetFinalizer.
Looking at https://github.com/golang/go/blob/master/src/runtime/mfinal.go#L388 https://github.com/golang/go/blob/master/src/runtime/mfinal.... it seems to be doing a lot, not just storing a function pointer somewhere. There are bunch of validations on the object type and the type of function that is being passed - like it should not be variadic, it should only accept one param and that first param should be of type of the object on which the finalizer is being set.
- jhgg 3y agoThese are all reasonable things to do at compile time, however for historical reasons since go did not have generics till recently, this is probably the best they can do without compiler specific specialization (eg what was done prior for maps and slices).