Skip to content

perf: unsafe.WriteSlice (#501)#503

Merged
gbotrel merged 7 commits intomasterfrom
perf/points_to_bytes
May 4, 2024
Merged

perf: unsafe.WriteSlice (#501)#503
gbotrel merged 7 commits intomasterfrom
perf/points_to_bytes

Conversation

@gbotrel
Copy link
Copy Markdown
Collaborator

@gbotrel gbotrel commented May 4, 2024

#501 can't be rebased -- recreating the PR on top of master.

  • refactor: expose pedersen basis slices
  • feat: more elegant solution to mem dump using unsafe and generics

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.

  • Adds utils/unsafe with WriteSlice[S ~[]E, E any](w io.Writer, s S) error ... ;
  • kzg.UnsafeToBytes(...) []byte is now WriteDump(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)

benchmark                                      old ns/op      new ns/op      delta
BenchmarkSerializeSRS/WriteTo-10               1227334792     1200767042     -2.16%
BenchmarkSerializeSRS/WriteRawTo-10            1291239625     1275224792     -1.24%
BenchmarkSerializeSRS/UnsafeToBytes-10         288414938      49002102       -83.01%
BenchmarkDeserializeSRS/UnsafeReadFrom-10      1589721583     1607936042     +1.15%
BenchmarkDeserializeSRS/UnsafeFromBytes-10     283540219      81233306       -71.35%

benchmark                                      old allocs     new allocs     delta
BenchmarkSerializeSRS/WriteTo-10               540            540            +0.00%
BenchmarkSerializeSRS/WriteRawTo-10            542            541            -0.18%
BenchmarkSerializeSRS/UnsafeToBytes-10         522            512            -1.92%
BenchmarkDeserializeSRS/UnsafeReadFrom-10      1046           1047           +0.10%
BenchmarkDeserializeSRS/UnsafeFromBytes-10     1029           1031           +0.19%

benchmark                                      old bytes      new bytes      delta
BenchmarkSerializeSRS/WriteTo-10               2147544696     2147544696     +0.00%
BenchmarkSerializeSRS/WriteRawTo-10            4295028640     4295028632     -0.00%
BenchmarkSerializeSRS/UnsafeToBytes-10         1610821246     67176202       -95.83%
BenchmarkDeserializeSRS/UnsafeReadFrom-10      1627598752     1627598848     +0.00%
BenchmarkDeserializeSRS/UnsafeFromBytes-10     1610820720     1610820744     +0.00%

@gbotrel gbotrel merged commit 564b6f7 into master May 4, 2024
@gbotrel gbotrel deleted the perf/points_to_bytes branch May 4, 2024 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant