awnumar/memguard

proposal: API change: export normal functions instead of methods

nsajko opened this issue · 5 comments

Memguard currently exports a lot of methods, almost none of which are associated with interfaces. It would thus probably be good to replace the methods in Memguard with the usual functions, because of the performance overhead of methods.

Note that this does not conflict with #68 , as additional methods to implement io interfaces can be added later.

Can you give an example?

Do you mean, for example, replacing func (*LockedBuffer) Bytes() []byte with func Bytes(*LockedBuffer) []byte?

Yes.

I have serious doubts that would impact performance in a significant way, especially relative to the heavy lifting being done within the methods themselves. I am happy to be proven wrong, but the benefits would have to outweigh the loss of ergonomics and the breaking change to facilitate them.

almost none of which are associated with interfaces

Why is this of note?

I might be misremembering that whole "methods have performance overhead relative to non-receiver functions" thing, sorry. I thought that there is additional run time indirection associated with method calls, but after searching the web I can not find any mention of that and I can not be bothered to check the assembly currently, so I am closing the issue, at least for now.

BTW, what I am sure of is that interfaces have a run-time cost, but that does not matter for Memguard.