Skip to content

Commit

Permalink
Slightly optimize masto-id-convert and update (#621)
Browse files Browse the repository at this point in the history
* slightly optimize and up

* rm uuid dev dep

* update snapshot

* update benches

* update docs

* add nixos ident
  • Loading branch information
aumetra authored Dec 12, 2024
1 parent 6eeb95d commit 5c2fc1f
Show file tree
Hide file tree
Showing 9 changed files with 541 additions and 338 deletions.
519 changes: 289 additions & 230 deletions Cargo.lock

Large diffs are not rendered by default.

57 changes: 27 additions & 30 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ aliri_braid = "0.4.0"
arc-swap = "1.7.1"
argh = "0.1.12"
argon2 = { version = "0.5.3", features = ["std"] }
async-graphql = { version = "7.0.11", default-features = false, features = [
async-graphql = { version = "7.0.13", default-features = false, features = [
"graphiql",
"tempfile",
"time",
"tracing",
"uuid",
] }
async-graphql-axum = "7.0.11"
async-graphql-axum = "7.0.13"
async-trait = "0.1.83"
asynk-strim = "0.1.2"
axum = { version = "0.7.9", features = ["macros", "multipart"] }
Expand All @@ -107,16 +107,16 @@ base64-simd = "0.8.0"
blake3 = "1.5.5"
bubble-bath = "0.2.1"
bytes = "1.9.0"
chrono = { version = "0.4.38", default-features = false }
clap = { version = "4.5.21", features = ["derive", "wrap_help"] }
chrono = { version = "0.4.39", default-features = false }
clap = { version = "4.5.23", features = ["derive", "wrap_help"] }
color-eyre = "0.6.3"
colored_json = "5.0.0"
const_format = "0.2.33"
const_format = "0.2.34"
const-oid = { version = "0.9.6", features = ["db"] }
cookie = { version = "0.18.1", features = ["percent-encode"] }
derive_builder = "0.20.2"
derive_more = { version = "1.0.0", features = ["from"] }
diesel = { version = "2.2.5", default-features = false, features = [
diesel = { version = "2.2.6", default-features = false, features = [
"32-column-tables",
"postgres_backend",
"uuid",
Expand All @@ -130,13 +130,13 @@ diesel-async = { version = "0.5.2", features = [
] }
diesel_full_text_search = { version = "2.2.0", default-features = false }
diesel_migrations = "2.2.0"
divan = "0.1.16"
divan = "0.1.17"
dotenvy = "0.15.7"
either = { version = "1.13.0", default-features = false }
enum_dispatch = "0.3.13"
envy = "0.4.2"
eyre = "0.6.12"
fred = { version = "10.0.0", features = [
fred = { version = "10.0.1", features = [
"enable-rustls-ring",
"full-tracing",
"i-scripts",
Expand Down Expand Up @@ -164,7 +164,7 @@ hickory-resolver = { version = "0.25.0-alpha.4", default-features = false, featu
"native-certs",
"tokio-runtime",
] }
http = "1.1.0"
http = "1.2.0"
http-body = "1.0.1"
http-body-util = "0.1.2"
httpdate = "1.0.3"
Expand All @@ -190,7 +190,7 @@ insta = { version = "1.41.1", default-features = false, features = [
"glob",
"json",
] }
iso8601-timestamp = { version = "0.3.1", features = ["diesel-pg"] }
iso8601-timestamp = { version = "0.3.2", features = ["diesel-pg"] }
isolang = { version = "2.4.0", features = [
"english_names",
"list_languages",
Expand All @@ -199,7 +199,7 @@ isolang = { version = "2.4.0", features = [
itertools = { version = "0.13.0", default-features = false }
lantern-client-sdk = { package = "client-sdk", git = "https://github.com/Lantern-chat/client-sdk-rs.git", rev = "efb4288d9b107b48609802193d57b29f7ae395a1", default-features = false }
leb128 = "0.2.5"
lettre = { version = "0.11.10", default-features = false, features = [
lettre = { version = "0.11.11", default-features = false, features = [
"builder",
"hostname",
"pool",
Expand All @@ -208,9 +208,9 @@ lettre = { version = "0.11.10", default-features = false, features = [
"tokio1-rustls-tls",
"tracing",
] }
lexical-parse-integer = { version = "1.0.2", default-features = false }
logos = "0.14.3"
lol_html = "2.0.0"
lexical-parse-integer = { version = "1.0.5", default-features = false }
logos = "0.15.0"
lol_html = "2.1.0"
meilisearch-sdk = { version = "0.27.1", default-features = false }
memchr = "2.7.4"
miette = { version = "7.4.0", features = ["fancy"] }
Expand All @@ -223,9 +223,6 @@ mrml = { version = "4.0.1", default-features = false, features = [
"parse",
"render",
] }
nanorand = { version = "0.7.0", default-features = false, features = [
"wyrand",
] }
notify-debouncer-full = "0.4.0"
num-derive = "0.4.2"
num-traits = "0.2.19"
Expand Down Expand Up @@ -272,15 +269,15 @@ quote = "1.0.37"
rand = "0.8.5"
rand_xorshift = "0.3.0"
rayon = "1.10.0"
redb = { version = "2.2.0", features = ["logging"] }
redb = { version = "2.3.0", features = ["logging"] }
regex = "1.11.1"
retry-policies = "0.4.0"
ring = { version = "0.17.8", features = ["std"] }
rsa = "0.9.7"
rstest = { version = "0.23.0", default-features = false }
rust-embed = { version = "8.5.0", features = ["include-exclude"] }
rustc-hash = "2.1.0"
rustls = { version = "0.23.19", default-features = false, features = [
rustls = { version = "0.23.20", default-features = false, features = [
"logging",
"ring",
"std",
Expand All @@ -292,10 +289,10 @@ sailfish = { version = "0.9.0", default-features = false, features = [
"derive",
"perf-inline",
] }
schemars = { version = "1.0.0-alpha.16", features = ["semver1"] }
schemars = { version = "1.0.0-alpha.17", features = ["semver1"] }
scoped-futures = { version = "0.1.4", default-features = false }
semver = { version = "1.0.23", features = ["serde"] }
serde = { version = "1.0.215", features = ["derive"] }
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.133"
serde_test = "1.0.177"
serde_urlencoded = "0.7.1"
Expand All @@ -313,14 +310,14 @@ subtle = "2.6.1"
syn = { version = "2.0.90", features = ["full"] }
sync_wrapper = "1.0.2"
tempfile = "3.14.0"
thiserror = "2.0.3"
time = "0.3.36"
tokio = { version = "1.41.1", features = ["full"] }
thiserror = "2.0.6"
time = "0.3.37"
tokio = { version = "1.42.0", features = ["full"] }
tokio-postgres = "0.7.12"
tokio-postgres-rustls = "0.13.0"
tokio-util = { version = "0.7.12", features = ["io", "rt"] }
tokio-util = { version = "0.7.13", features = ["io", "rt"] }
toml = { version = "0.8.19", default-features = false, features = ["parse"] }
tower = { version = "0.5.1", default-features = false, features = ["util"] }
tower = { version = "0.5.2", default-features = false, features = ["util"] }
tower-http = { version = "0.6.2", features = [
"catch-panic",
"cors",
Expand Down Expand Up @@ -349,14 +346,14 @@ triomphe = { version = "0.1.14", default-features = false, features = [
typed-builder = "0.20.0"
typetag = "0.2.18"
unsize = "1.1.0"
ureq = "2.11.0"
ureq = "2.12.1"
url = "2.5.4"
urlencoding = "2.1.3"
uuid = { version = "1.11.0", features = ["fast-rng", "v7"] }
uuid-simd = { version = "0.8.0", features = ["uuid"] }
walkdir = "2.5.0"
wasm-encoder = "0.221.0"
wasmparser = "0.221.0"
wasm-encoder = "0.221.2"
wasmparser = "0.221.2"
wasmtime = { version = "27.0.0", default-features = false, features = [
"addr2line",
"async",
Expand All @@ -367,7 +364,7 @@ wasmtime = { version = "27.0.0", default-features = false, features = [
"runtime",
] }
wasmtime-wasi = { version = "27.0.0", default-features = false }
wat = "1.221.0"
wat = "1.221.2"
whatlang = "0.16.4"
whichlang = "0.1.0"
wit-bindgen = "0.36.0"
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
doc-valid-idents = [
"ActivityPub",
"DoS",
"NixOS",
"OAuth",
"OAuth2",
"PostgreSQL",
"PubSub",
"WyRand",
"gRPC",
]
2 changes: 0 additions & 2 deletions lib/masto-id-convert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ harness = false

[dependencies]
lexical-parse-integer.workspace = true
nanorand.workspace = true
uuid.workspace = true

[dev-dependencies]
divan.workspace = true
time.workspace = true
uuid.workspace = true

[lints]
workspace = true
17 changes: 10 additions & 7 deletions lib/masto-id-convert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@ Convert a Mastodon snowflake ID into a UUID v7 while preserving the timestamp co

## How?

The unix timestamp is preserved as-is, the 2-bytes sequence is stretched out via the WyRand PRNG algorithm.
The unix timestamp is preserved as-is, the 2-bytes sequence is kept as-is since we expect the sequence to be already unique.

## Performance

Tested inside a WSL2 installation on a Ryzen 5 3600X:
Tested inside a NixOS installation on a Ryzen 7 7840U:

```text
process 110368129515784116
time: [16.675 ns 16.822 ns 17.037 ns]
change: [-1.2226% -0.3915% +0.4911%] (p = 0.37 > 0.05)
Timer precision: 20 ns
process fastest β”‚ slowest β”‚ median β”‚ mean β”‚ samples β”‚ iters
β”œβ”€ process ASCII β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ ╰─ 110368129515784116 20.82 ns β”‚ 192 ns β”‚ 20.98 ns β”‚ 24.25 ns β”‚ 100 β”‚ 12800
╰─ process integer β”‚ β”‚ β”‚ β”‚ β”‚
╰─ 110368129515784116 14.13 ns β”‚ 17.18 ns β”‚ 14.17 ns β”‚ 14.2 ns β”‚ 100 β”‚ 25600
```

Processing a single Mastodon snowflake takes ~17ns
Processing a single Mastodon snowflake takes ~14ns

## License

`masto-id-convert` is licensed under the [MIT license](http://opensource.org/licenses/MIT).

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you,
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you,
shall be licensed as above, without any additional terms or conditions.
Loading

0 comments on commit 5c2fc1f

Please sign in to comment.