diff --git a/CHANGELOG/CHANGELOG-1.x.md b/CHANGELOG/CHANGELOG-1.x.md index 0f423ed..6450630 100644 --- a/CHANGELOG/CHANGELOG-1.x.md +++ b/CHANGELOG/CHANGELOG-1.x.md @@ -17,6 +17,20 @@ Date format: `YYYY-MM-DD` ### Fixed ### Security +--- +## [1.20.0] - 2024-11-16 + +### Added +### Changed +- **FEATURE:** Updated the [PRNG](../x/crypto/prng) reader to allow for each reader instance to have its own `sync.Pool` for buffer reuse. +- **DEBT:** Refactored to not use `strings.Builder` for ID generation in favor of `sync.Pool` for buffer reuse. +- **DEBT:** Modified [README.md](README.md) to include detailed information about `sync.Pool` usage for buffer reuse for both ASCII and Unicode ID generation. + +### Deprecated +### Removed +### Fixed +### Security + --- ## [1.19.0] - 2024-11-16 @@ -27,7 +41,7 @@ Date format: `YYYY-MM-DD` - **DEBT:** Updated [PRNG](../x/crypto/prng) benchmark tests to test the standard size of 21 characters for Nano ID generation. - **DEBT:** The runtime configuration (`Config`) now uses pointer receivers for all methods to ensure consistent behavior and interface compliance. - **DEBT:** Refactored Codebase: Split the `nanoid.go` file into multiple modular files within the `nanoid` package to enhance code organization, readability, and maintainability -- + ### Deprecated ### Removed ### Fixed @@ -462,7 +476,8 @@ Date format: `YYYY-MM-DD` ### Fixed ### Security -[Unreleased]: https://github.com/sixafter/nanoid/compare/v1.19.0..HEAD +[Unreleased]: https://github.com/sixafter/nanoid/compare/v1.20.0..HEAD +[1.20.0]: https://github.com/sixafter/nanoid/compare/v1.19.0...v1.20.0 [1.19.0]: https://github.com/sixafter/nanoid/compare/v1.18.1...v1.19.0 [1.18.1]: https://github.com/sixafter/nanoid/compare/v1.18.0...v1.18.1 [1.18.0]: https://github.com/sixafter/nanoid/compare/v1.17.3...v1.18.0 diff --git a/README.md b/README.md index aa3400a..12511cf 100644 --- a/README.md +++ b/README.md @@ -239,7 +239,7 @@ Generated ID: A8I8K3J0QY The nanoid generator utilizes `sync.Pool` to manage byte slice buffers efficiently. This approach minimizes memory allocations and enhances performance, especially in high-concurrency scenarios. How It Works: -* Storing Pointers: `sync.Pool` stores pointers to `[]byte` slices (`*[]byte`) instead of the slices themselves. This avoids unnecessary allocations and aligns with best practices for using `sync.Pool`. +* Storing Pointers: `sync.Pool` stores pointers to `[]byte` (or `[]rune` if Unicode) slices (`*[]byte`) instead of the slices themselves. This avoids unnecessary allocations and aligns with best practices for using `sync.Pool`. * Zeroing Buffers: Before returning buffers to the pool, they are zeroed out to prevent data leaks. ### Struct Optimization @@ -267,167 +267,167 @@ goos: darwin goarch: arm64 pkg: github.com/sixafter/nanoid cpu: Apple M4 Max -BenchmarkNanoIDAllocations-16 14318704 81.72 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDAllocationsConcurrent-16 67763110 16.15 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_DefaultLength-16 15188494 78.37 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_2-16 35454968 34.53 ns/op 8 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_3-16 32779533 37.05 ns/op 8 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_5-16 29836489 40.66 ns/op 8 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_13-16 20298000 57.49 ns/op 16 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_21-16 16523661 72.90 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_34-16 11567829 102.5 ns/op 48 B/op 1 allocs/op -BenchmarkGenerator_Read_ZeroLengthBuffer-16 899398803 1.334 ns/op 0 B/op 0 allocs/op -BenchmarkGenerator_Read_Concurrent/Concurrency_1-16 15924032 73.68 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_Concurrent/Concurrency_2-16 30869953 39.47 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_Concurrent/Concurrency_4-16 53020219 25.02 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_Concurrent/Concurrency_8-16 71823493 16.26 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_Concurrent/Concurrency_16-16 74829878 14.44 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen8-16 26380341 45.18 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen16-16 19585760 62.57 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen21-16 16327316 71.70 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen32-16 12858915 92.76 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen64-16 7864554 152.7 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen128-16 4521963 263.0 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen8-16 26724024 44.68 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen16-16 19288508 61.47 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen21-16 16651855 71.67 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen32-16 13239339 91.09 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen64-16 7927832 151.5 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen128-16 4585581 260.9 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen8-16 27092953 44.56 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen16-16 19397608 61.66 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen21-16 16790154 71.77 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen32-16 12921525 92.47 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen64-16 7786845 152.0 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen128-16 4586020 261.5 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen8-16 26981778 44.63 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen16-16 19697626 61.33 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen21-16 16638607 72.65 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen32-16 12382740 94.72 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen64-16 7822154 152.6 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen128-16 4571776 272.1 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen8-16 19501108 62.13 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen16-16 12258480 96.82 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen21-16 10284886 114.7 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen32-16 7772995 154.8 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen64-16 4410819 272.0 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen128-16 2386099 501.8 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen8-16 19307736 63.37 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen16-16 12347330 96.57 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen21-16 10350645 118.9 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen32-16 7597382 156.7 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen64-16 4367085 273.9 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen128-16 2380953 506.9 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen8-16 19134736 62.90 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen16-16 12492582 96.04 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen21-16 10391311 115.0 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen32-16 7725854 156.2 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen64-16 4314513 273.6 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen128-16 2381019 502.9 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen8-16 19200831 63.52 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen16-16 12389340 96.67 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen21-16 10312555 116.3 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen32-16 7659938 155.7 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen64-16 4388805 273.1 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen128-16 2385751 503.7 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen8-16 137644742 7.789 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen16-16 100000000 10.73 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen21-16 93969322 13.68 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen32-16 62877154 17.81 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen64-16 40507353 30.00 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen128-16 23519860 52.73 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen8-16 148337209 8.224 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen16-16 100000000 10.73 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen21-16 80615584 13.32 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen32-16 67688575 17.66 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen64-16 40898517 28.74 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen128-16 24600330 50.13 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen8-16 148020730 8.096 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen16-16 100000000 10.78 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen21-16 91318411 14.07 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen32-16 71116905 16.99 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen64-16 40690780 28.13 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen128-16 24042754 49.82 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen8-16 155735688 7.741 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen16-16 100000000 11.15 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen21-16 88183687 13.26 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen32-16 67886580 16.79 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen64-16 42262760 28.11 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen128-16 24148390 48.57 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen8-16 95122332 12.57 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen16-16 59121673 22.50 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen21-16 43497828 27.08 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen32-16 32718980 36.79 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen64-16 17846673 66.96 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen128-16 9805506 121.8 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen8-16 94081983 13.57 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen16-16 57457389 22.33 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen21-16 39253527 31.03 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen32-16 30329932 39.87 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen64-16 17305892 71.16 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen128-16 9408576 127.4 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen8-16 90432381 13.56 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen16-16 44038987 23.46 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen21-16 40879766 30.02 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen32-16 30454308 41.64 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen64-16 15016314 74.21 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen128-16 9485343 130.4 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen8-16 88650294 13.24 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen16-16 53983129 21.90 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen21-16 39779500 28.94 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen32-16 29728940 38.54 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen64-16 16351167 68.58 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen128-16 9917641 122.0 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen8-16 23241456 45.42 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen16-16 18732742 65.11 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen21-16 15977692 72.47 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen32-16 12448131 99.06 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen64-16 7415142 164.3 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen128-16 4145812 289.2 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen8-16 25051995 45.72 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen16-16 19202598 62.73 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen21-16 16435147 73.21 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen32-16 12831844 94.21 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen64-16 7704615 157.2 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen128-16 4425217 276.7 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen8-16 25598953 45.57 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen16-16 19057614 62.66 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen21-16 16212391 73.10 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen32-16 12844366 92.96 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen64-16 7733532 159.5 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen128-16 4260783 281.7 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen8-16 24486859 47.67 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen16-16 18676666 63.38 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen21-16 16334020 73.24 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen32-16 12672018 94.54 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen64-16 7721707 155.3 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen128-16 4483032 267.4 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen8-16 19529527 62.71 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen16-16 12396213 97.23 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen21-16 10278896 116.3 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen32-16 7664722 156.0 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen64-16 4357148 275.2 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen128-16 2366166 507.0 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen8-16 18755970 63.63 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen16-16 12390586 97.43 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen21-16 10318215 116.0 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen32-16 7675764 156.4 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen64-16 4367828 274.9 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen128-16 2368156 506.0 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen8-16 19273186 62.95 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen16-16 12282088 97.11 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen21-16 10248876 116.5 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen32-16 7676949 156.4 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen64-16 4373037 273.8 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen128-16 2372378 505.9 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen8-16 19010188 63.21 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen16-16 12517303 96.70 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen21-16 10282838 116.2 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen32-16 7661167 156.4 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen64-16 4359604 274.6 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen128-16 2369816 506.8 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDAllocations-16 15003954 76.30 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDAllocationsConcurrent-16 74179202 15.76 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_DefaultLength-16 16803123 68.10 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_2-16 33585614 36.13 ns/op 2 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_3-16 31765290 38.20 ns/op 3 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_5-16 28791708 42.14 ns/op 5 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_13-16 22228155 55.78 ns/op 16 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_21-16 18243597 65.63 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_34-16 13976239 86.27 ns/op 48 B/op 1 allocs/op +BenchmarkGenerator_Read_ZeroLengthBuffer-16 816275398 1.372 ns/op 0 B/op 0 allocs/op +BenchmarkGenerator_Read_Concurrent/Concurrency_1-16 17746567 66.30 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_Concurrent/Concurrency_2-16 33351552 36.08 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_Concurrent/Concurrency_4-16 55830726 21.93 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_Concurrent/Concurrency_8-16 60704806 18.97 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_Concurrent/Concurrency_16-16 67446042 16.91 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen8-16 25284205 46.18 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen16-16 20124421 58.75 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen21-16 18030165 65.83 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen32-16 14527756 82.23 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen64-16 8959059 134.7 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen128-16 5327983 225.5 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen8-16 24694173 45.10 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen16-16 20262411 57.76 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen21-16 18349347 65.79 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen32-16 14576307 81.71 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen64-16 8961514 133.6 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen128-16 5336977 224.3 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen8-16 26897259 46.21 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen16-16 20310639 58.69 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen21-16 17752453 67.27 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen32-16 14871600 80.86 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen64-16 9064250 134.2 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen128-16 5340874 223.6 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen8-16 26052786 45.81 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen16-16 20089396 57.76 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen21-16 18227050 65.65 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen32-16 14711966 81.99 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen64-16 8971347 134.5 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen128-16 5296887 226.6 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen8-16 16784506 70.18 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen16-16 11497441 104.4 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen21-16 9549919 125.2 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen32-16 6733585 178.0 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen64-16 3697659 326.2 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen128-16 1986321 607.8 ns/op 289 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen8-16 17139867 69.70 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen16-16 11514620 104.0 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen21-16 9670254 123.7 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen32-16 6933122 173.9 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen64-16 3671619 324.5 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen128-16 1984659 601.5 ns/op 289 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen8-16 17377945 68.67 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen16-16 11687414 103.8 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen21-16 9423592 126.0 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen32-16 6661424 179.6 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen64-16 3693400 322.7 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen128-16 1993962 604.1 ns/op 289 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen8-16 17084515 69.71 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen16-16 11476266 103.1 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen21-16 9785174 125.6 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen32-16 6641458 178.9 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen64-16 3680024 325.8 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen128-16 1970880 608.1 ns/op 289 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen8-16 155731814 7.966 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen16-16 100000000 10.72 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen21-16 88434433 12.91 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen32-16 76901302 15.83 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen64-16 44088199 26.29 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen128-16 25929686 45.83 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen8-16 159970467 7.688 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen16-16 100000000 10.46 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen21-16 91863391 12.60 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen32-16 71162065 15.79 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen64-16 44062299 26.30 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen128-16 26455730 44.79 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen8-16 162121165 7.687 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen16-16 100000000 10.86 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen21-16 83806197 13.03 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen32-16 75761760 15.57 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen64-16 45690134 25.44 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen128-16 26845486 44.60 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen8-16 160724536 7.605 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen16-16 100000000 10.66 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen21-16 91057120 12.44 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen32-16 75076638 15.30 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen64-16 45273408 26.00 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen128-16 26638818 44.49 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen8-16 86501292 12.93 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen16-16 54813188 20.64 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen21-16 53420488 22.20 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen32-16 36231016 31.31 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen64-16 22430011 53.27 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen128-16 12645932 96.45 ns/op 288 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen8-16 93198150 12.98 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen16-16 58279538 19.86 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen21-16 55201494 21.39 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen32-16 37473552 31.02 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen64-16 22530309 53.32 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen128-16 12306376 96.18 ns/op 288 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen8-16 88192876 12.87 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen16-16 57457620 20.01 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen21-16 53846470 21.74 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen32-16 37763508 31.43 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen64-16 22099260 54.05 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen128-16 12431437 96.13 ns/op 288 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen8-16 84577526 12.84 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen16-16 58122990 19.93 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen21-16 52644855 21.77 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen32-16 37568679 31.45 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen64-16 22077678 54.60 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen128-16 12427960 96.53 ns/op 288 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen8-16 24682723 45.65 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen16-16 19997860 59.69 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen21-16 17316693 69.90 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen32-16 13858519 86.02 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen64-16 8383051 144.3 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen128-16 4923039 243.1 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen8-16 25041670 46.75 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen16-16 19813886 60.98 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen21-16 17404220 69.12 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen32-16 13892030 85.15 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen64-16 8509674 141.9 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen128-16 4921491 241.0 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen8-16 25172382 47.19 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen16-16 19663951 60.46 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen21-16 17468212 68.51 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen32-16 14062369 85.35 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen64-16 8480640 141.5 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen128-16 5044694 238.8 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen8-16 26560914 45.30 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen16-16 19941325 60.39 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen21-16 17160159 68.94 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen32-16 13838980 86.89 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen64-16 8455816 140.1 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen128-16 5122021 234.6 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen8-16 16634562 71.56 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen16-16 11221044 107.0 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen21-16 9227674 129.0 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen32-16 6767592 178.3 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen64-16 3574780 333.7 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen128-16 1922041 628.0 ns/op 288 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen8-16 16603988 70.65 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen16-16 11450854 106.3 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen21-16 9321528 128.2 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen32-16 6649005 182.6 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen64-16 3578170 333.0 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen128-16 1946996 617.6 ns/op 288 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen8-16 16661652 71.52 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen16-16 11298946 106.5 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen21-16 9353600 128.5 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen32-16 6632572 179.0 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen64-16 3584874 333.7 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen128-16 1914860 624.4 ns/op 288 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen8-16 16383211 70.89 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen16-16 11173053 107.2 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen21-16 9277276 128.6 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen32-16 6546392 182.6 ns/op 80 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen64-16 3611689 334.5 ns/op 144 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen128-16 1939897 618.9 ns/op 288 B/op 1 allocs/op PASS -ok github.com/sixafter/nanoid 211.634s +ok github.com/sixafter/nanoid 210.925s ``` diff --git a/nanoid.go b/nanoid.go index 4f00f86..96e83d8 100644 --- a/nanoid.go +++ b/nanoid.go @@ -8,7 +8,6 @@ package nanoid import ( "encoding/binary" "fmt" - "strings" "sync" "github.com/sixafter/nanoid/x/crypto/prng" @@ -274,14 +273,14 @@ func NewGenerator(options ...Option) (Generator, error) { if config.isASCII { idPool = &sync.Pool{ New: func() interface{} { - buf := make([]byte, 0, config.bufferSize*config.bufferMultiplier) + buf := make([]byte, config.bufferSize*config.bufferMultiplier) return &buf }, } } else { idPool = &sync.Pool{ New: func() interface{} { - buf := make([]rune, 0, config.bufferSize*config.bufferMultiplier) + buf := make([]rune, config.bufferSize*config.bufferMultiplier) return &buf }, } @@ -344,19 +343,23 @@ func (g *generator) newASCII(length int) (ID, error) { randomBytes := *randomBytesPtr bufferLen := len(randomBytes) + // Defer returning the randomBytes buffer to the pool + defer func() { + g.entropyPool.Put(randomBytesPtr) + }() + cursor := 0 maxAttempts := length * maxAttemptsMultiplier mask := g.config.mask bytesNeeded := g.config.bytesNeeded isPowerOfTwo := g.config.isPowerOfTwo - // Use strings.Builder to build the ID efficiently - var sb strings.Builder - sb.Grow(length) // Preallocate capacity to minimize allocations + // Retrieve the idBuffer from the pool + idBufferPtr := g.idPool.Get().(*[]byte) + idBuffer := (*idBufferPtr)[:length] // Ensure it has the correct length - // Defer returning the randomBytes buffer to the pool defer func() { - g.entropyPool.Put(randomBytesPtr) + g.idPool.Put(idBufferPtr) }() for attempts := 0; cursor < length && attempts < maxAttempts; attempts++ { @@ -376,7 +379,7 @@ func (g *generator) newASCII(length int) (ID, error) { rnd &= mask if isPowerOfTwo || int(rnd) < int(g.config.alphabetLen) { - sb.WriteByte(g.config.byteAlphabet[rnd]) + idBuffer[cursor] = g.config.byteAlphabet[rnd] cursor++ } } @@ -387,7 +390,7 @@ func (g *generator) newASCII(length int) (ID, error) { return EmptyID, ErrExceededMaxAttempts } - return ID(sb.String()), nil + return ID(idBuffer), nil } // newUnicode generates a new Nano ID using the Unicode alphabet. @@ -397,20 +400,23 @@ func (g *generator) newUnicode(length int) (ID, error) { randomBytes := *randomBytesPtr bufferLen := len(randomBytes) + // Defer returning the randomBytes buffer to the pool + defer func() { + g.entropyPool.Put(randomBytesPtr) + }() + cursor := 0 maxAttempts := length * maxAttemptsMultiplier mask := g.config.mask bytesNeeded := g.config.bytesNeeded isPowerOfTwo := g.config.isPowerOfTwo - var sb strings.Builder + // Retrieve the idBuffer from the pool + idBufferPtr := g.idPool.Get().(*[]rune) + idBuffer := (*idBufferPtr)[:length] // Ensure it has the correct length - // Use the precomputed maximum bytes per rune to estimate buffer size - sb.Grow(length * g.config.maxBytesPerRune) - - // Defer returning the randomBytes buffer to the pool defer func() { - g.entropyPool.Put(randomBytesPtr) + g.idPool.Put(idBufferPtr) }() for attempts := 0; cursor < length && attempts < maxAttempts; attempts++ { @@ -430,7 +436,7 @@ func (g *generator) newUnicode(length int) (ID, error) { rnd &= mask if isPowerOfTwo || int(rnd) < int(g.config.alphabetLen) { - sb.WriteRune(g.config.runeAlphabet[rnd]) + idBuffer[cursor] = g.config.runeAlphabet[rnd] cursor++ } } @@ -441,7 +447,7 @@ func (g *generator) newUnicode(length int) (ID, error) { return EmptyID, ErrExceededMaxAttempts } - return ID(sb.String()), nil + return ID(idBuffer), nil } // Reader is the interface that wraps the basic Read method. diff --git a/x/crypto/prng/prng.go b/x/crypto/prng/prng.go index 4d2cf17..72a3f50 100644 --- a/x/crypto/prng/prng.go +++ b/x/crypto/prng/prng.go @@ -31,10 +31,20 @@ import ( // // Handle error // } // fmt.Printf("Read %d bytes of random data: %x\n", n, buffer) -var Reader io.Reader = &poolReader{} +var Reader io.Reader -// poolReader is a custom io.Reader that uses a sync.Pool to manage prng instances. -type poolReader struct{} +func init() { + var err error + Reader, err = NewReader() + if err != nil { + panic(fmt.Sprintf("prng.init: failed to create Reader: %v", err)) + } +} + +// reader is a custom io.Reader that uses a sync.Pool to manage prng instances. +type reader struct { + prngPool *sync.Pool +} // NewReader returns a new instance that implements the io.Reader interface. // This instance can be used for cryptographically secure, pseudo-random byte generation. @@ -53,7 +63,18 @@ type poolReader struct{} // } // fmt.Printf("Read %d bytes of random data: %x\n", n, buffer) func NewReader() (io.Reader, error) { - return &poolReader{}, nil + return &reader{ + &sync.Pool{ + New: func() interface{} { + p, err := newPRNG() + if err != nil { + // Instead of panicking, return an errorPRNG instance with the error. + return &errorPRNG{err: fmt.Errorf("prngPool.New: failed to create prng: %v", err)} + } + return p + }, + }, + }, nil } // Read fills the provided byte slice 'b' with random data generated by a prng instance from the pool. @@ -70,9 +91,9 @@ func NewReader() (io.Reader, error) { // // Handle error // } // fmt.Printf("Read %d bytes of random data: %x\n", n, buffer) -func (r *poolReader) Read(b []byte) (int, error) { - p := prngPool.Get().(io.Reader) - defer prngPool.Put(p) +func (r *reader) Read(b []byte) (int, error) { + p := r.prngPool.Get().(io.Reader) + defer r.prngPool.Put(p) return p.Read(b) } @@ -150,18 +171,3 @@ func (p *prng) Read(b []byte) (int, error) { p.stream.XORKeyStream(b, p.zero) return len(b), nil } - -// prngPool is a sync.Pool that holds prng instances to reduce contention on crypto/rand.Reader. -// It allows multiple goroutines to acquire separate prng instances for concurrent random byte generation. -// -// Each prng instance is either a valid prng or an errorPRNG if initialization failed. -var prngPool = sync.Pool{ - New: func() interface{} { - p, err := newPRNG() - if err != nil { - // Instead of panicking, return an errorPRNG instance with the error. - return &errorPRNG{err: fmt.Errorf("prngPool.New: failed to create prng: %v", err)} - } - return p - }, -}