-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: more elegant solution to mem dump using unsafe and generics #501
Conversation
📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Imo we can add a simple guard in case the slice to write is empty to have better errors, but I think normally shouldn't happen.
return err | ||
} | ||
|
||
data := unsafe.Slice((*byte)(unsafe.Pointer(&s[0])), size*len(s)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add guard in case len(s) == 0
.
Motivation; enable other gnark objects (like
groth16.ProvingKey
) to be written and read very fast (though not portable). Limit code duplication between curves, fields, proof systems, etc.utils/unsafe
withWriteSlice[S ~[]E, E any](w io.Writer, s S) error
... ;kzg.UnsafeToBytes(...) []byte
is nowWriteDump(w io.Writer) error
🔥 Benchmarks for kzg SRS dump 🔥 --> (I mean using
unsafe
is a cheat, we just benchmark the non-unsafe method + real IO)