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

Improve decoding performance #81

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

steveluscher
Copy link
Contributor

@steveluscher steveluscher commented Apr 13, 2023

This yields a performance improvement over indexing into source over and over. source is asserted to be a string, psz is monotonically increasing, and psz >= source.length is a good indication that you've run out of characters.

Originally proposed by @oscxc in #74.

Benchmarks

cd benchmark/
(cd ../ && npm run build) && SEED=8854dc2a353e143702ef1b29874b63a4 npm start

Before

> base-x-benchmark@0.0.0 start
> node index.js

Seed: 8854dc2a353e143702ef1b29874b63a4
--------------------------------------------------
encode x 389,286 ops/sec ±0.21% (8 runs sampled)
decode x 415,231 ops/sec ±0.91% (9 runs sampled)
==================================================

After

> base-x-benchmark@0.0.0 start
> node index.js

Seed: 8854dc2a353e143702ef1b29874b63a4
--------------------------------------------------
encode x 389,695 ops/sec ±0.12% (9 runs sampled)
decode x 449,877 ops/sec ±0.13% (9 runs sampled)
==================================================

This yields a performance improvement over indexing into `source` over and over. `source` is asserted to be a string, `psz` is monotonically increasing, and `psz >= source.length` is a good indication that you've run out of characters.

Originally proposed by @oscxc in cryptocoinjs#74.

Co-authored-by: Rand <15077550@qq.com>
@steveluscher
Copy link
Contributor Author

Rebased on top of @Nesopie's ESM changes. Let's get this in!

@junderw junderw merged commit 64e196c into cryptocoinjs:master Jul 4, 2024
3 checks passed
@steveluscher steveluscher deleted the this-but-faster branch July 4, 2024 00:53
@steveluscher
Copy link
Contributor Author

You don’t feel like backporting this to bs58 version 4.x, do you @junderw? There are reasons we can’t upgrade to v6 and have to stay on 4.x.

@junderw
Copy link
Member

junderw commented Jul 4, 2024

Give me a list of commands to backport and publish all these backports without updating the npm latest tag for everything, and I'll consider running those commands when I have free time.

It would probably take me a few minutes to find everything, cherry-pick, push a branch for previous major version(s) push a tag to Github, publish to npm under a new non-latest tag etc. And then I would need to do the same for bs58 and bump the dependency etc.

Probably about 15-20 minutes of work depending on how much I can concentrate without messing up.

But if you give me a list of commands and I can check that they're sane, running them would be a few seconds.

Assuming base-x and bs58 are sibling directories and these repos are origin remotes is fine.

@steveluscher
Copy link
Contributor Author

steveluscher commented Jul 4, 2024

For sure!

# Rewind to base-x@3.0.9
cd base-x
git checkout v3.0.9
git clean -dfx .
npm i

# Backport change, build, and test
git cherry-pick 261fb3636147815a7705375cfe7c1217db15e8f5
rm -rf src
npm run build
git add -A
git cherry-pick --continue --no-edit
npm run test

# Publish base-x@3.0.10
npm version 3.0.10  # automatically adds the git tag v3.0.10
npm publish --tag bp  # avoids updating the latest tag on npm
npm dist-tag rm base-x bp  # deletes the temporary npm tag we just created

# Create a backport branch for posterity and push the whole thing to Github
git checkout -b v3.x
git push origin v3.x  # the branch
git push origin v3.0.10  # the tag

That's it. bs58@4.0.1 will pick up this new version by virtue of it depending on base-x@^3.0.2. No need to backport anything to bs58.

@junderw
Copy link
Member

junderw commented Jul 4, 2024

ok, should be published.

@steveluscher
Copy link
Contributor Author

Thank you!

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