Skip to content

Reduce size by new url generation and counter reuse#170

Merged
ai merged 6 commits into
ai:masterfrom
gwer:f/reduce_size_with_random_in_loop
Jan 30, 2020
Merged

Reduce size by new url generation and counter reuse#170
ai merged 6 commits into
ai:masterfrom
gwer:f/reduce_size_with_random_in_loop

Conversation

@gwer

@gwer gwer commented Jan 28, 2020

Copy link
Copy Markdown
Contributor

Url generation based on @anber_ru's proposal.

@Anber

Anber commented Jan 28, 2020

Copy link
Copy Markdown

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

Comment thread async/index.browser.js Outdated
Comment thread async/index.browser.js Outdated
Comment thread async/index.browser.js
Comment thread async/index.browser.js
Comment thread async/index.browser.js
Comment thread async/index.browser.js Outdated
@ai

ai commented Jan 29, 2020

Copy link
Copy Markdown
Owner

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

@gwer

gwer commented Jan 30, 2020

Copy link
Copy Markdown
Contributor Author
$ 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

ai commented Jan 30, 2020

Copy link
Copy Markdown
Owner

Released in 2.1.11

Comment thread async/index.browser.js
Comment on lines +29 to +30
var bytes = crypto.getRandomValues(new Uint8Array(size || 21))
i = size || 21

Copy link
Copy Markdown

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
Copy Markdown
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Really? o:

Copy link
Copy Markdown
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

Copy link
Copy Markdown

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