base58_native 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3bf3eae735d06293c2adad78fba335b7c5c56f6cad8e8efdb71df29fdda537c9
4
+ data.tar.gz: f802a69515e65175d3c1092d0bde29a69e627c19f85317f703db1482a31dfd33
5
+ SHA512:
6
+ metadata.gz: df4a15b635b740de162df0d91a9c29a763469c5460166cc36cc89ccfe63bdbb138bab3a79b841dfbc92d7d54d9e372b65df718564f0451a962ae07a007d327fe
7
+ data.tar.gz: 6bdfbae27957de11e4d64741b9acd18d29e2a8e4658d47f8b23d4238d8eebd7567cd722957fa817d6c32460827fd4678ee209471f0ef1d8905656e8a92287d66
data/Cargo.lock ADDED
@@ -0,0 +1,294 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "1.1.5"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "base58_codec"
16
+ version = "0.1.0"
17
+
18
+ [[package]]
19
+ name = "base58_native"
20
+ version = "0.1.0"
21
+ dependencies = [
22
+ "base58_codec",
23
+ "bytes",
24
+ "magnus",
25
+ ]
26
+
27
+ [[package]]
28
+ name = "bindgen"
29
+ version = "0.72.1"
30
+ source = "registry+https://github.com/rust-lang/crates.io-index"
31
+ checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
32
+ dependencies = [
33
+ "bitflags",
34
+ "cexpr",
35
+ "clang-sys",
36
+ "itertools",
37
+ "proc-macro2",
38
+ "quote",
39
+ "regex",
40
+ "rustc-hash",
41
+ "shlex",
42
+ "syn",
43
+ ]
44
+
45
+ [[package]]
46
+ name = "bitflags"
47
+ version = "2.13.2"
48
+ source = "registry+https://github.com/rust-lang/crates.io-index"
49
+ checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
50
+
51
+ [[package]]
52
+ name = "bytes"
53
+ version = "1.12.1"
54
+ source = "registry+https://github.com/rust-lang/crates.io-index"
55
+ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
56
+
57
+ [[package]]
58
+ name = "cexpr"
59
+ version = "0.6.0"
60
+ source = "registry+https://github.com/rust-lang/crates.io-index"
61
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
62
+ dependencies = [
63
+ "nom",
64
+ ]
65
+
66
+ [[package]]
67
+ name = "cfg-if"
68
+ version = "1.0.5"
69
+ source = "registry+https://github.com/rust-lang/crates.io-index"
70
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
71
+
72
+ [[package]]
73
+ name = "clang-sys"
74
+ version = "1.9.1"
75
+ source = "registry+https://github.com/rust-lang/crates.io-index"
76
+ checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a"
77
+ dependencies = [
78
+ "glob",
79
+ "libc",
80
+ "libloading",
81
+ ]
82
+
83
+ [[package]]
84
+ name = "either"
85
+ version = "1.19.0"
86
+ source = "registry+https://github.com/rust-lang/crates.io-index"
87
+ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
88
+
89
+ [[package]]
90
+ name = "glob"
91
+ version = "0.3.4"
92
+ source = "registry+https://github.com/rust-lang/crates.io-index"
93
+ checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
94
+
95
+ [[package]]
96
+ name = "itertools"
97
+ version = "0.13.0"
98
+ source = "registry+https://github.com/rust-lang/crates.io-index"
99
+ checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
100
+ dependencies = [
101
+ "either",
102
+ ]
103
+
104
+ [[package]]
105
+ name = "lazy_static"
106
+ version = "1.5.1"
107
+ source = "registry+https://github.com/rust-lang/crates.io-index"
108
+ checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
109
+
110
+ [[package]]
111
+ name = "libc"
112
+ version = "0.2.191"
113
+ source = "registry+https://github.com/rust-lang/crates.io-index"
114
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
115
+
116
+ [[package]]
117
+ name = "libloading"
118
+ version = "0.8.9"
119
+ source = "registry+https://github.com/rust-lang/crates.io-index"
120
+ checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
121
+ dependencies = [
122
+ "cfg-if",
123
+ "windows-link",
124
+ ]
125
+
126
+ [[package]]
127
+ name = "magnus"
128
+ version = "0.9.4"
129
+ source = "registry+https://github.com/rust-lang/crates.io-index"
130
+ checksum = "3c5f2dd2017d172e2fde9969a35f10f1374a4dd79b37a17f1847f83201883de7"
131
+ dependencies = [
132
+ "bytes",
133
+ "magnus-macros",
134
+ "rb-sys",
135
+ "rb-sys-env",
136
+ "seq-macro",
137
+ ]
138
+
139
+ [[package]]
140
+ name = "magnus-macros"
141
+ version = "0.9.1"
142
+ source = "registry+https://github.com/rust-lang/crates.io-index"
143
+ checksum = "9dafde2eeb66f090e0f326112323eb8324b12cb32b5d1210e541d3df6b0ce77e"
144
+ dependencies = [
145
+ "proc-macro2",
146
+ "quote",
147
+ "syn",
148
+ ]
149
+
150
+ [[package]]
151
+ name = "memchr"
152
+ version = "2.8.3"
153
+ source = "registry+https://github.com/rust-lang/crates.io-index"
154
+ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
155
+
156
+ [[package]]
157
+ name = "minimal-lexical"
158
+ version = "0.2.1"
159
+ source = "registry+https://github.com/rust-lang/crates.io-index"
160
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
161
+
162
+ [[package]]
163
+ name = "nom"
164
+ version = "7.1.3"
165
+ source = "registry+https://github.com/rust-lang/crates.io-index"
166
+ checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
167
+ dependencies = [
168
+ "memchr",
169
+ "minimal-lexical",
170
+ ]
171
+
172
+ [[package]]
173
+ name = "proc-macro2"
174
+ version = "1.0.107"
175
+ source = "registry+https://github.com/rust-lang/crates.io-index"
176
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
177
+ dependencies = [
178
+ "unicode-ident",
179
+ ]
180
+
181
+ [[package]]
182
+ name = "quote"
183
+ version = "1.0.47"
184
+ source = "registry+https://github.com/rust-lang/crates.io-index"
185
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
186
+ dependencies = [
187
+ "proc-macro2",
188
+ ]
189
+
190
+ [[package]]
191
+ name = "rb-sys"
192
+ version = "0.9.130"
193
+ source = "registry+https://github.com/rust-lang/crates.io-index"
194
+ checksum = "02faf625bb10ba893e3ae620f19c9fb1b5f8fcae0fe4eb86bb3f2230fad75edb"
195
+ dependencies = [
196
+ "rb-sys-build",
197
+ ]
198
+
199
+ [[package]]
200
+ name = "rb-sys-build"
201
+ version = "0.9.130"
202
+ source = "registry+https://github.com/rust-lang/crates.io-index"
203
+ checksum = "05be6f9c86fe5482808162826f6c047d093b3670582296c770de1d94f8066694"
204
+ dependencies = [
205
+ "bindgen",
206
+ "lazy_static",
207
+ "proc-macro2",
208
+ "quote",
209
+ "regex",
210
+ "shell-words",
211
+ "syn",
212
+ ]
213
+
214
+ [[package]]
215
+ name = "rb-sys-env"
216
+ version = "0.2.3"
217
+ source = "registry+https://github.com/rust-lang/crates.io-index"
218
+ checksum = "cca7ad6a7e21e72151d56fe2495a259b5670e204c3adac41ee7ef676ea08117a"
219
+
220
+ [[package]]
221
+ name = "regex"
222
+ version = "1.13.2"
223
+ source = "registry+https://github.com/rust-lang/crates.io-index"
224
+ checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
225
+ dependencies = [
226
+ "aho-corasick",
227
+ "memchr",
228
+ "regex-automata",
229
+ "regex-syntax",
230
+ ]
231
+
232
+ [[package]]
233
+ name = "regex-automata"
234
+ version = "0.4.19"
235
+ source = "registry+https://github.com/rust-lang/crates.io-index"
236
+ checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
237
+ dependencies = [
238
+ "aho-corasick",
239
+ "memchr",
240
+ "regex-syntax",
241
+ ]
242
+
243
+ [[package]]
244
+ name = "regex-syntax"
245
+ version = "0.8.12"
246
+ source = "registry+https://github.com/rust-lang/crates.io-index"
247
+ checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
248
+
249
+ [[package]]
250
+ name = "rustc-hash"
251
+ version = "2.1.3"
252
+ source = "registry+https://github.com/rust-lang/crates.io-index"
253
+ checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
254
+
255
+ [[package]]
256
+ name = "seq-macro"
257
+ version = "0.3.6"
258
+ source = "registry+https://github.com/rust-lang/crates.io-index"
259
+ checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
260
+
261
+ [[package]]
262
+ name = "shell-words"
263
+ version = "1.1.1"
264
+ source = "registry+https://github.com/rust-lang/crates.io-index"
265
+ checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"
266
+
267
+ [[package]]
268
+ name = "shlex"
269
+ version = "1.3.0"
270
+ source = "registry+https://github.com/rust-lang/crates.io-index"
271
+ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
272
+
273
+ [[package]]
274
+ name = "syn"
275
+ version = "2.0.119"
276
+ source = "registry+https://github.com/rust-lang/crates.io-index"
277
+ checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
278
+ dependencies = [
279
+ "proc-macro2",
280
+ "quote",
281
+ "unicode-ident",
282
+ ]
283
+
284
+ [[package]]
285
+ name = "unicode-ident"
286
+ version = "1.0.27"
287
+ source = "registry+https://github.com/rust-lang/crates.io-index"
288
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
289
+
290
+ [[package]]
291
+ name = "windows-link"
292
+ version = "0.2.1"
293
+ source = "registry+https://github.com/rust-lang/crates.io-index"
294
+ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
data/Cargo.toml ADDED
@@ -0,0 +1,8 @@
1
+ [workspace]
2
+ members = ["ext/base58_native", "ext/base58_codec"]
3
+ resolver = "2"
4
+
5
+ [profile.release]
6
+ lto = true
7
+ codegen-units = 1
8
+ opt-level = 3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pocketflows
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # base58_native
2
+
3
+ Fast Base58 encoding of UUIDs, hex strings and integers for Ruby, implemented
4
+ in safe Rust. It is a behaviour-identical replacement for Pocketflows'
5
+ pure-Ruby `Base58` (the short public ids used across the app), and is
6
+ **~40–60x faster** on the UUID paths under YJIT.
7
+
8
+ ```ruby
9
+ # Gemfile
10
+ gem "base58_native"
11
+ ```
12
+
13
+ Precompiled gems are built for `x86_64-linux`, `aarch64-linux` (glibc) and
14
+ `arm64-darwin` (Apple Silicon). Each one bundles a binary for Ruby 3.3, 3.4
15
+ and 4.0, so installing on those platforms does **not** need a Rust
16
+ toolchain. Other platforms (Alpine/musl, Intel Macs, Windows) fall back to the
17
+ source gem, which compiles with `cargo`.
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require "base58_native"
23
+
24
+ Base58Native.encode_from_uuid("550e8400-e29b-41d4-a716-446655440000") # => "BWBeN28Vb7cMEx7Ym8AUzs"
25
+ Base58Native.decode_to_uuid("BWBeN28Vb7cMEx7Ym8AUzs") # => "550e8400-e29b-41d4-a716-446655440000"
26
+
27
+ Base58Native.encode_from_hex("ff") # => "5Q"
28
+ Base58Native.decode_to_hex("5Q") # => "ff"
29
+ Base58Native.encode_from_base10(255) # => "5Q"
30
+ Base58Native.decode_to_base10("5Q") # => 255
31
+
32
+ Base58Native.decode_to_uuid("not0valid") # raises Base58Native::DecodeError
33
+ Base58Native.decode_to_uuid("z" * 22) # raises Base58Native::InvalidUUIDError
34
+ Base58Native.native? # => true when the Rust extension is loaded
35
+ ```
36
+
37
+ `Base58Native::DecodeError` and `Base58Native::InvalidUUIDError` both inherit
38
+ from `Base58Native::Error < StandardError`. To use them where code rescues the
39
+ original `Base58::DecodeError` / `Base58::InvalidUUIDError`, alias the
40
+ constants:
41
+
42
+ ```ruby
43
+ class Base58
44
+ DecodeError = Base58Native::DecodeError
45
+ InvalidUUIDError = Base58Native::InvalidUUIDError
46
+ end
47
+ ```
48
+
49
+ ## Parity with the original Ruby `Base58`
50
+
51
+ Results and errors match the original implementation for **every** input,
52
+ including odd ones. That covers return values, `String#encoding`
53
+ (`decode_to_hex` returns US-ASCII like `Integer#to_s`, everything else is
54
+ UTF-8), the exception class and message, and the lenient parsing inherited
55
+ from `Integer(hex, 16)` (`"0x1f"`, `" 1f "`, `"-1f"`, `"1_f"`). Here is how:
56
+
57
+ * The Rust fast path accepts only the strict, common shapes: canonical or
58
+ dash-free hex UUIDs, `[0-9A-Fa-f]+`, strings from the Base58 alphabet, and
59
+ non-negative Integers, all for values below 2**128 and in UTF-8, US-ASCII
60
+ or ASCII-8BIT strings.
61
+ * Anything else goes, unchanged, to `Base58Native::Fallback`. That is a
62
+ verbatim port of the original Ruby code, so it produces exactly the
63
+ original result or exception. This covers malformed input, values wider
64
+ than 128 bits, other encodings and other argument types.
65
+
66
+ `require "base58_native/parity"` exposes the differential harness used by the
67
+ test suite. Point it at your own reference implementation:
68
+
69
+ ```ruby
70
+ cases = Base58Native::Parity.cases # ~25k typical and adversarial inputs
71
+ Base58Native::Parity.each_mismatch(Base58, Base58Native, cases) do |method, arg, expected, actual|
72
+ raise "#{method}(#{arg.inspect}): #{expected.inspect} != #{actual.inspect}"
73
+ end
74
+ ```
75
+
76
+ `test/reference/base58.rb` is a verbatim copy of the original
77
+ `lib/base58.rb`. The tests diff the native extension and the fallback against
78
+ it, including under `GC.stress`, `GC.compact` and threads.
79
+
80
+ ## Safety
81
+
82
+ The extension is designed so it cannot crash the Ruby process:
83
+
84
+ * **No `unsafe`.** `unsafe_code = "forbid"` is set for both crates.
85
+ * **No panicking constructs.** `unwrap`, `expect`, `panic!`, `unreachable!`
86
+ and slice indexing are all denied by clippy. Table lookups use `.get()`,
87
+ and arithmetic is either provably in range or `checked_*`.
88
+ * **Belt and braces.** Every entry point runs under `catch_unwind`. A
89
+ hypothetical panic would surface as a rescuable `Base58Native::Error`,
90
+ never magnus's process-ending `fatal`.
91
+ * **Avoids panicking or slow magnus helpers.** `Integer::to_u128` and
92
+ `integer_from_u128` go through decimal strings, and the latter `unwrap`s
93
+ internally. The extension uses bignum arithmetic and hex formatting instead.
94
+ * **Fallback when the native library can't load.** If it fails to load (for
95
+ example on an unsupported platform without Rust), the gem warns and serves
96
+ every call from the pure-Ruby fallback, so behaviour is still correct.
97
+
98
+ The pure codec lives in its own crate (`ext/base58_codec`) and has no Ruby
99
+ dependency. Its unit tests check it against `std` formatting and naive
100
+ reference algorithms in debug builds (with overflow checks) and in release
101
+ builds.
102
+
103
+ ## Performance
104
+
105
+ These numbers compare the original Ruby implementation, run with Ruby 3.4.13
106
+ and YJIT, against this gem (`bundle exec rake bench`). There are two
107
+ environments: macOS on Apple Silicon, and Linux aarch64 (the precompiled gem
108
+ in `ruby:3.4.13-slim` under Docker on the same machine). Runs vary by about
109
+ ±15%.
110
+
111
+ | method | Ruby (YJIT) | native | speedup (macOS) | speedup (Linux) |
112
+ | --- | ---: | ---: | ---: | ---: |
113
+ | `encode_from_uuid` | ~2.7 µs | ~65 ns | **~40x** | **~50x** |
114
+ | `decode_to_uuid` | ~3.7 µs | ~60 ns | **~55–65x** | **~85x** |
115
+ | `encode_from_hex` | ~2.3 µs | ~70 ns | **~30–35x** | **~40x** |
116
+ | `decode_to_hex` | ~3.4 µs | ~65 ns | **~50x** | **~80x** |
117
+ | `decode_to_base10` | ~3.4 µs | ~115 ns | **~30x** | **~28x** |
118
+ | `encode_from_base10` (128-bit) | ~2.2 µs | ~170 ns | **~12x** | **~17x** |
119
+ | `encode_from_base10` (small int) | ~320 ns | ~27 ns | **~12x** | **~13x** |
120
+
121
+ Roughly 45 ns of a UUID call is Ruby-boundary cost: about 5 ns of method
122
+ dispatch, about 15 ns to copy the argument's bytes (magnus has no safe
123
+ borrowed view of a Ruby string), and about 21 ns to allocate the result
124
+ String. The Base58 arithmetic itself is about 8 ns. See
125
+ `ext/base58_codec/examples/micro.rs`:
126
+
127
+ ```
128
+ cargo run --release --example micro -p base58_codec
129
+ ```
130
+
131
+ ## Development
132
+
133
+ `test/reference/base58.rb` is a verbatim copy of the original Ruby
134
+ implementation. Tests, `rake parity` and `rake bench` all run against it, so
135
+ the gem can be iterated on by itself. Set `REFERENCE=/path/to/base58.rb` to
136
+ compare against a different copy, such as code-3's live file.
137
+
138
+ ```sh
139
+ bundle install
140
+ bundle exec rake compile # build the extension into lib/
141
+ bundle exec rake cargo # Rust unit tests (debug + release) and clippy
142
+ bundle exec rake test # full Ruby parity suite (GC stress, compaction, threads)
143
+ bundle exec rake parity # quick differential check vs the vendored reference
144
+ bundle exec rake bench # native vs the vendored reference, YJIT
145
+ ```
146
+
147
+ ### Precompiled gems
148
+
149
+ ```sh
150
+ bundle exec rake gem:native # Docker + rb-sys-dock: pkg/base58_native-<v>-{x86_64-linux,aarch64-linux,arm64-darwin}.gem
151
+ bundle exec rake gem:verify # each gem has a correct-arch binary for Ruby 3.3/3.4/4.0 and no runtime deps
152
+ bundle exec rake gem:smoke # install the Linux gems on stock ruby:*-slim images (no Rust) and run test/smoke.rb
153
+ ```
154
+
155
+ Use `PLATFORMS=arm64-darwin bundle exec rake gem:native` to build a subset.
156
+
157
+ ### Releasing
158
+
159
+ Releases go through Bundler's standard `rake release`, run from a
160
+ maintainer's machine. You need Docker, Rust (for the source-gem check) and
161
+ `gem signin` with access to `base58_native`.
162
+
163
+ ```sh
164
+ # 1. bump lib/base58_native/version.rb, commit on main
165
+ git commit -am "Bump version to 0.1.1"
166
+
167
+ # 2. optional dry run: build, verify and smoke-test every gem; publishes nothing
168
+ bundle exec rake release:native
169
+
170
+ # 3. release
171
+ bundle exec rake release
172
+ ```
173
+
174
+ `rake release` runs these steps in order:
175
+
176
+ 1. Builds the source gem and checks that the tree is clean.
177
+ 2. Runs `release:native`: builds the three platform gems, checks them with
178
+ `gem:verify`, and smoke-tests the Linux gems on stock Ruby images with
179
+ `gem:smoke`. It also installs the Mac gem and the source gem into clean gem
180
+ homes and tests them.
181
+ 3. Tags `v0.1.1`, then pushes `main` and the tag.
182
+ 4. Runs `gem push` on the platform gems first, then the source gem.
183
+
184
+ If step 2 fails, nothing has been tagged or pushed. `gem_push=no bundle exec
185
+ rake release` tags and pushes git without publishing to RubyGems.
186
+
187
+ ## License
188
+
189
+ MIT
@@ -0,0 +1,20 @@
1
+ [package]
2
+ name = "base58_codec"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ rust-version = "1.88"
6
+ publish = false
7
+ license = "MIT"
8
+ description = "Panic-free 128-bit Base58 codec used by the base58_native gem"
9
+
10
+ [lints.rust]
11
+ unsafe_code = "forbid"
12
+
13
+ [lints.clippy]
14
+ unwrap_used = "deny"
15
+ expect_used = "deny"
16
+ panic = "deny"
17
+ indexing_slicing = "deny"
18
+ unreachable = "deny"
19
+ todo = "deny"
20
+ unimplemented = "deny"
@@ -0,0 +1,73 @@
1
+ //! cargo run --release --example micro -p base58_codec
2
+ #![allow(clippy::indexing_slicing, clippy::unwrap_used)]
3
+ use std::hint::black_box;
4
+ use std::time::Instant;
5
+
6
+ use base58_codec::*;
7
+
8
+ fn main() {
9
+ let mut x: u128 = 0x1234_5678_9abc_def0_0fed_cba9_8765_4321;
10
+ let vals: Vec<u128> = (0..1024)
11
+ .map(|_| {
12
+ x ^= x << 13;
13
+ x ^= x >> 7;
14
+ x ^= x << 17;
15
+ x
16
+ })
17
+ .collect();
18
+ let uuids: Vec<[u8; 36]> = vals.iter().map(|&v| format_uuid(v)).collect();
19
+ let encs: Vec<Vec<u8>> = vals
20
+ .iter()
21
+ .map(|&v| {
22
+ let mut b = [0u8; MAX_B58_LEN];
23
+ let s = encode_u128(v, &mut b);
24
+ b.get(s..).unwrap_or(&[]).to_vec()
25
+ })
26
+ .collect();
27
+ const ITERS: usize = 20_000_000;
28
+
29
+ let bench = |name: &str, f: &dyn Fn(usize) -> u64| {
30
+ let mut acc = 0u64;
31
+ for i in 0..ITERS / 10 {
32
+ acc = acc.wrapping_add(f(i));
33
+ }
34
+ let t = Instant::now();
35
+ for i in 0..ITERS {
36
+ acc = acc.wrapping_add(f(i));
37
+ }
38
+ let ns = t.elapsed().as_nanos() as f64 / ITERS as f64;
39
+ println!("{name:<24} {ns:6.2} ns ({})", acc & 1);
40
+ };
41
+
42
+ bench("parse_canonical_uuid", &|i| {
43
+ parse_canonical_uuid(black_box(&uuids[i & 1023])).unwrap_or(0) as u64
44
+ });
45
+ bench("parse_hex(skip dashes)", &|i| {
46
+ parse_hex(black_box(&uuids[i & 1023]), true).unwrap_or(0) as u64
47
+ });
48
+ bench("encode_u128", &|i| {
49
+ let mut b = [0u8; MAX_B58_LEN];
50
+ let s = encode_u128(black_box(vals[i & 1023]), &mut b);
51
+ black_box(&b);
52
+ s as u64
53
+ });
54
+ bench("u128 / 58^10 only", &|i| {
55
+ (black_box(vals[i & 1023]) / 430_804_206_899_405_824u128) as u64
56
+ });
57
+ bench("baseline (lookup only)", &|i| {
58
+ black_box(vals[i & 1023]) as u64
59
+ });
60
+ bench("decode_u128", &|i| {
61
+ decode_u128(black_box(&encs[i & 1023])).unwrap_or(0) as u64
62
+ });
63
+ bench("format_uuid", &|i| {
64
+ let b = format_uuid(black_box(vals[i & 1023]));
65
+ black_box(&b);
66
+ b[0] as u64
67
+ });
68
+ bench("format_hex", &|i| {
69
+ let (b, s) = format_hex(black_box(vals[i & 1023]));
70
+ black_box(&b);
71
+ s as u64
72
+ });
73
+ }