Skip to content
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

Feat/fasterer #4

Merged
merged 4 commits into from
Jun 2, 2020
Merged

Feat/fasterer #4

merged 4 commits into from
Jun 2, 2020

Conversation

ribasushi
Copy link
Contributor

image

The core change is this

go-base36/base36.go

Lines 50 to 59 in 986b8a8

// It is crucial to make this as short as possible, especially for
// the usual case of CIDs.
bufsz = zcnt +
// This is an integer simplification of
// ceil(log(256)/log(36))
(bufsz-zcnt)*277/179 + 1
// Note: pools *DO NOT* help, the overhead of zeroing
// kills any performance gain to be had
out := make([]byte, bufsz)
We now allocate just as much as we need, and iterate over the buffer in place: once to breakdown into values, and a second time to recode into an alphabet.

  • before
go-multibase$ go test ./... -count=1 -bench .
goos: darwin
goarch: amd64
pkg: github.com/multiformats/go-multibase
BenchmarkRoundTrip/base36-8         	  326816	      3599 ns/op
BenchmarkRoundTrip/base36upper-8    	  332366	      3571 ns/op
BenchmarkRoundTrip/base58btc-8      	  481983	      2551 ns/op
BenchmarkRoundTrip/base58flickr-8   	  470001	      2556 ns/op
BenchmarkEncode/base36-8            	  435662	      2788 ns/op
BenchmarkEncode/base36upper-8       	  440614	      2788 ns/op
BenchmarkEncode/base58btc-8         	  770272	      1568 ns/op
BenchmarkEncode/base58flickr-8      	  700389	      1562 ns/op
BenchmarkDecode/base36-8            	 1606472	       745 ns/op
BenchmarkDecode/base36upper-8       	 1614858	       744 ns/op
BenchmarkDecode/base58btc-8         	 1245900	       952 ns/op
BenchmarkDecode/base58flickr-8      	 1259892	       956 ns/op
PASS
  • after
go-multibase$ go test ./... -count=1 -bench .
goos: darwin
goarch: amd64
pkg: github.com/multiformats/go-multibase
BenchmarkRoundTrip/base36-8         	  432175	      2750 ns/op
BenchmarkRoundTrip/base36upper-8    	  436525	      2723 ns/op
BenchmarkRoundTrip/base58btc-8      	  466893	      2553 ns/op
BenchmarkRoundTrip/base58flickr-8   	  475454	      2547 ns/op
BenchmarkEncode/base36-8            	  601210	      1933 ns/op
BenchmarkEncode/base36upper-8       	  629655	      1938 ns/op
BenchmarkEncode/base58btc-8         	  791280	      1572 ns/op
BenchmarkEncode/base58flickr-8      	  795505	      1555 ns/op
BenchmarkDecode/base36-8            	 1558412	       766 ns/op
BenchmarkDecode/base36upper-8       	 1561417	       762 ns/op
BenchmarkDecode/base58btc-8         	 1250644	       954 ns/op
BenchmarkDecode/base58flickr-8      	 1263541	       954 ns/op
PASS

P.S. If you look closely you see that the decoding became marginally slower. To the best of my ability to reason it has to do with the total compiled object size. That is - if you revert 986b8a84d74, then the decoding number goes back to where it was, even though the reverted commit does not touch the decode method 🤯

Also with this in place switching to uint32 is worth it
@ribasushi ribasushi mentioned this pull request May 23, 2020
@ribasushi
Copy link
Contributor Author

👍
I'll tag this as part of multiformats/go-multibase#37 soon, want to let b58 bake a bit more...

@ribasushi ribasushi merged commit d1cbc7a into master Jun 2, 2020
@ribasushi ribasushi deleted the feat/fasterer branch June 2, 2020 20:20
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.

2 participants