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

Reduce size by new url generation and counter reuse #170

Merged
merged 6 commits into from
Jan 30, 2020

Conversation

gwer
Copy link
Contributor

@gwer gwer commented Jan 28, 2020

Url generation based on @anber_ru's proposal.

@Anber
Copy link

Anber commented Jan 28, 2020

You forgot about non-secure/index.js and url.js. Also, the comment about low entropy is obsolete :)

async/index.browser.js Outdated Show resolved Hide resolved
async/index.browser.js Outdated Show resolved Hide resolved
async/index.browser.js Outdated Show resolved Hide resolved
@ai
Copy link
Owner

ai commented Jan 29, 2020

Ещё нужно сравнить результаты test/benchmark до и после этого PR

@gwer
Copy link
Contributor Author

gwer commented Jan 30, 2020

$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

$ node test/benchmark
nanoid                    282,863 ops/sec
nanoid/generate           255,983 ops/sec
uid.sync                  170,236 ops/sec
uuid/v4                   202,241 ops/sec
secure-random-string      189,137 ops/sec
shortid                    30,185 ops/sec

Async:
nanoid/async               31,993 ops/sec
nanoid/async/generate      31,449 ops/sec
secure-random-string       30,437 ops/sec
uid                        29,401 ops/sec

Non-secure:
nanoid/non-secure       1,714,070 ops/sec
rndm                    1,593,879 ops/sec

$ git checkout -
Switched to branch 'f/reduce_size_with_random_in_loop'
Your branch is up to date with 'origin/f/reduce_size_with_random_in_loop'.

$ node test/benchmark
nanoid                    294,016 ops/sec
nanoid/generate           265,646 ops/sec
uid.sync                  201,971 ops/sec
uuid/v4                   219,655 ops/sec
secure-random-string      183,223 ops/sec
shortid                    28,493 ops/sec

Async:
nanoid/async               33,153 ops/sec
nanoid/async/generate      30,710 ops/sec
secure-random-string       28,456 ops/sec
uid                        28,692 ops/sec

Non-secure:
nanoid/non-secure       1,552,124 ops/sec
rndm                    1,683,481 ops/sec

@gwer gwer changed the title Reduce size by new url generation and getRandomValues in loop Reduce size by new url generation and counter reuse Jan 30, 2020
@ai ai merged commit 9c080ef into ai:master Jan 30, 2020
@ai
Copy link
Owner

ai commented Jan 30, 2020

Released in 2.1.11

Comment on lines +29 to +30
var bytes = crypto.getRandomValues(new Uint8Array(size || 21))
i = size || 21

Choose a reason for hiding this comment

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

Why not?

  i = size || 21
  var bytes = crypto.getRandomValues(new Uint8Array(i))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For better gzip compression. It makes +1 byte.

Choose a reason for hiding this comment

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

Really? o:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I was wrong. +3 bytes :D

Choose a reason for hiding this comment

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

Haha

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.

4 participants