Skip to content

Conversation

@holiman
Copy link
Contributor

@holiman holiman commented Dec 15, 2020

This PR optimises the hashing a bit during the snap response verification. We use a hash only temporarily, to verify against the request, and can thus reuse the same buffer, and avoid an alloc and copy. We can also use the keccatState to avoid a second alloc+copy via Read instead of Sum.

Benchmark for checking 10K items with 100 bytes of data each:

BenchmarkHashing/old
BenchmarkHashing/old-6         	     100	  20599259 ns/op	 5120510 B/op	   30002 allocs/op
BenchmarkHashing/new
BenchmarkHashing/new-6         	     219	   5355205 ns/op	     480 B/op	       2 allocs/op

@holiman holiman added this to the 1.10.0 milestone Dec 21, 2020
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hash := make([]byte, 32), Go usually either uses var for the default value or := for non defaults. Pls also add a newline after this.

Pls update the others too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squashfixed

Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@karalabe karalabe merged commit 4bb5c6c into ethereum:master Jan 7, 2021
Copy link

@DGKSK8LIFE DGKSK8LIFE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting change; lgtm

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.

3 participants