r/rust • • 14h ago

πŸ—žοΈ news Official Announcement: Rust, Post-Quantum Cryptography, and You

Thumbnail rustfoundation.org
390 Upvotes

r/rust • • 16h ago

πŸ—žοΈ news New trait solver is now enabled by default on nightly!

Thumbnail github.com
280 Upvotes

r/rust • • 23h ago

If you use Tokio, change the default allocator

Thumbnail dial9-rs.github.io
185 Upvotes

r/rust • • 18h ago

wgpu v31 has been released!

118 Upvotes

r/rust • • 9h ago

The Embedded Rustacean Issue #86

Thumbnail theembeddedrustacean.com
17 Upvotes

r/rust • • 19h ago

πŸŽ™οΈ discussion How do you monitor Rust web applications in production?

9 Upvotes

Disclosure: I maintain StatLite, an open-source monitoring tool that I use for my own applications running on small VPS.

I've been asked about Rust support, so I started exploring the monitoring options for Axum and Actix Web.

I've added lightweight instrumentation recipes for both frameworks. They collect request counts, HTTP errors, average response time, process CPU, and RSS - without requiring an additional monitoring crate.

In my experiments, these recipes had a smaller binary size, lower memory overhead, and a significantly smaller metrics payload than the Prometheus-based instrumentation I tested.

The recipes and benchmark results are here:

I'm also considering native integration with existing Prometheus exporters, so users don't need to add custom instrumentation.

I wonder what people here actually use to monitor their Rust applications. Prometheus, OpenTelemetry, something simpler? Are there particular libraries you'd recommend supporting?

I'd be happy to add native integrations if there is interest.


r/rust • • 17h ago

πŸ™‹ seeking help & advice Leptos not generating JS and WASM files

2 Upvotes

Leptos not generating JS and WASM files when I cargo leptos watch. It does generate the css file in the target/site/pkg. It will buld the saite, but the site has no functionality. I have spent waaay too long on this and just want it running like it should. Any help? There is not git repo, only local so the error is confusing when I use verbose. Other wise no error... I can see as the terminal cuts off before it ends.

Note: I am

cargo leptos build -v

Location:
C:\Users\me\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\cargo-leptos-0.3.10\src\command\build.rs:25
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1: git_filter_source_repo<unknown> at <unknown source file>:<unknown line>
2: git_filter_source_repo<unknown> at <unknown source file>:<unknown line>
3: git_diff_stats_to_buf<unknown> at <unknown source file>:<unknown line>
4: BaseThreadInitThunk<unknown> at <unknown source file>:<unknown line>
5: RtlUserThreadStart<unknown> at <unknown source file>:<unknown line>

.cargo/config.toml

#to stop a recursation involving thaw going 130 levels deep
[build]
rustflags = ["--cfg", "erase_components"]

lib.rs

pub mod app;
pub mod db;


#[cfg(feature = "hydrate")]
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn hydrate() {
Β  Β  use crate::app::*;
Β  Β  console_error_panic_hook::set_once();
Β  Β  leptos::mount::hydrate_body(App);
}

Cargo.toml

[package]
name = "example-leptos"
version = "0.1.0"
edition = "2021"


[lib]
crate-type = ["cdylib", "rlib"]


[dependencies]
leptos = { version = "0.8.23", features = ["ssr"] }
leptos_router = { version = "0.8.17" }
axum = { version = "0.8.8", features = ["ws", "macros", "multipart", "http2"], optional = true }
axum-extra = { version = "0.12.5", features = ["protobuf", "multipart", "typed-header"], optional = true}
axum-server = Β { version = "0.9.0", features = ["tls-rustls"], optional = true }
console_error_panic_hook = { version = "0.1", optional = true }
leptos_axum = { version = "0.8.0", optional = true }
leptos_meta = { version = "0.8.7" }
tokio = { version = "1.54.1", features = ["macros", "rt-multi-thread"], optional = true }
wasm-bindgen = { version = "0.2.130", optional = true }
wasm-bindgen-futures = { version = "0.4", optional = true }
cookie = { version = "0.18.1", optional = true }
blob = "0.3.0"
bytes = "1.9.0"
bytes-utils = "0.1.4"
chrono = { version = "0.4.44", features = ["alloc","serde"]}
derivative = "2.1.0"
dotenv = "0.15.0"
env_logger = "0.11.6"
fred = { version = "10.0.4", features = ["serde-json", "enable-rustls", "rustls"], optional = true }
futures = "0.3.34"
futures-util = "0.3.34"
generic-array = "1.4.5"
hex-literal = "1.0.0"
http = "1.5.0"
image = "0.25.6"
lazy_static = "1.5.0"
lettre = "0.11.23"
lettre_email = "0.9.4"
log = "0.4.34"
rand = "0.10.3"
reqwest = { version = "0.13.5", features = ["json"] }
rust_decimal = "1.43.0"
serde = { version = "1.0.229", features = ["derive"] }
serde_json = "1.0.151"
sqlx = { version = "0.9.0", features = ["rust_decimal", "postgres", "runtime-tokio", "tls-rustls", "uuid", "chrono"], optional = true }
thiserror = "2.0.21"
tokio-task-scheduler = { version = "1.0.0", optional = true }
tower-http = { version = "0.7.1", features = ["compression-br", "compression-gzip","limit", "trace","cors","fs"], optional = true }
tower-sessions = { version = "0.15.0", optional = true }
tower-sessions-core = { version = "0.15.0", optional = true }
tower-sessions-redis-store = { version = "0.17.0", optional = true }
tower_governor = { version = "0.8.0", optional = true }
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.22", features = ["env-filter"] }
webauthn-rs = { version = "0.6.2", features = ["danger-allow-state-serialisation", "danger-credential-internals"], optional = true }
thaw = { version = "0.5.0-beta", features = ["ssr"] }
leptos-remix-icon = "1.0.3"
leptos-use = "0.20.0"
icondata_core = "0.1.0"
tower = { version = "0.5.3", optional = true }
cfg-if = "1.0.5"
icondata = "0.7.0"
meilisearch-sdk = { version = "0.33.0", optional = true }
leptos_meilisearch = "0.7.0"
dotenvy = "0.15.7"
leptos-use-window = "0.20.1"
time = "0.3.55"


[dependencies.web-sys]
version = "0.3.107"
optional = true
features = ["AbortController", "AbortSignal", "AuthenticationExtensionsClientOutputs", "AuthenticatorResponse", "Clipboard", "CredentialCreationOptions", "CredentialRequestOptions", "CredentialsContainer", "DomException", "Element", "Event", "Headers", "HtmlCollection", "HtmlSelectElement", "Navigator", "PublicKeyCredential", "PublicKeyCredentialCreationOptions", "PublicKeyCredentialRpEntity", "PublicKeyCredentialUserEntity", "Request", "RequestCredentials", "RequestInit", "RequestMode", "RequestRedirect", "Response", "Window"]


[dependencies.webauthn-rs-proto]
version = "0.6.2"
default-features = false
features = ["wasm"]


[features]
hydrate = [
Β  Β  "leptos/hydrate",
Β  Β  "thaw/hydrate",
Β  Β  "dep:console_error_panic_hook",
Β  Β  "dep:wasm-bindgen",
Β  Β  "dep:wasm-bindgen-futures",
Β  Β  "dep:web-sys",
]
ssr = [
Β  Β  "dep:axum",
Β  Β  "dep:axum-extra",
Β  Β  "dep:axum-server",
Β  Β  "dep:cookie",
Β  Β  "dep:tokio",
Β  Β  "dep:tokio-task-scheduler",
Β  Β  "dep:leptos_axum",
Β  Β  "dep:fred",
Β  Β  "dep:sqlx",
Β  Β  "dep:tower",
Β  Β  "dep:tower-http",
Β  Β  "dep:tower-sessions",
Β  Β  "dep:tower-sessions-core",
Β  Β  "dep:tower-sessions-redis-store",
Β  Β  "dep:meilisearch-sdk",
Β  Β  "dep:webauthn-rs",
Β  Β  "dep:tower_governor",
Β  Β  "leptos/ssr",
Β  Β  "leptos-use/ssr",
Β  Β  "leptos_meta/ssr",
Β  Β  "leptos_router/ssr",
Β  Β  "thaw/ssr",
]


[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.4.3", features = ["wasm_js"] }
[target.'cfg(target_arch = "wasm64")'.dependencies]
getrandom = { version = "0.4.3", features = ["wasm_js"] }


# Defines a size-optimized profile for the WASM bundle in release mode
[profile.wasm-release]
inherits = "release"
opt-level = 'z'
lto = true
codegen-units = 1
panic = "abort"


[package.metadata.cargo-all-features]
denylist = ["axum", "tower", "tower-http", "tokio", "sqlx", "leptos_axum"]
skip_feature_sets = [["ssr", "hydrate"]]


[package.metadata.leptos]
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "example-leptos"


# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
site-root = "target/site"


# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
# Defaults to pkg
site-pkg-dir = "pkg"


# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/example-leptos.css
style-file = "style/main.scss"
# Assets source dir. All files found here will be copied and synchronized to site-root.
# The assets-dir cannot have a sub directory with the same name/path as site-pkg-dir.
#
# Optional. Env: LEPTOS_ASSETS_DIR.
assets-dir = "public"


# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
site-addr = "127.0.0.1:3000"


# The port to use for automatic reload monitoring
reload-port = 3001


# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
# Β  [Windows] for non-WSL use "npx.cmd playwright test"
# Β  This binary name can be checked in Powershell with Get-Command npx
end2end-cmd = "npx playwright test"
end2end-dir = "end2end"


# Β The browserlist query used for optimizing the CSS.
browserquery = "defaults"


# The environment Leptos will run in, usually either "DEV" or "PROD"
env = "DEV"


# The features to use when compiling the bin target
#
# Optional. Can be over-ridden with the command line parameter --bin-features
bin-features = ["ssr"]


# If the --no-default-features flag should be used when compiling the bin target
#
# Optional. Defaults to false.
bin-default-features = false


# The features to use when compiling the lib target
#
# Optional. Can be over-ridden with the command line parameter --lib-features
lib-features = ["hydrate"]


# If the --no-default-features flag should be used when compiling the lib target
#
# Optional. Defaults to false.
lib-default-features = false


# The profile to use for the lib target when compiling for release
#
# Optional. Defaults to "release".
lib-profile-release = "wasm-release"

r/rust • • 11h ago

🧠 educational Devlog: Optimizing f64 GEMM from 6.5 to ~40 GFLOP/s with a BLIS-style micro-kernel

0 Upvotes

https://adii.fyi/blog/optimizing-matmul-in-rust-from-naive-loops-to-blis/

I wanted to see how far I could push a single-threaded f64 matmul. Started with the usual i-k-j loop, and then spent quite a bit of time looking at asm, then experimenting with SIMD, and eventually working through BLIS-style blocking and packing.

Writing this up was a good way to document the whole process, so thought I'd share it here.


r/rust • • 14h ago

πŸ› οΈ project leptos_wasi is now beating ntex and axum in our full-stack Rust benchmarks

Post image
0 Upvotes

"WebAssembly on the server will never beat native Rust."

I've been a Senior Rust SWE for 5 years, and for the last 2 of them I've been maintaining leptos_wasi taking it from 0.1 to 0.2, then 0.5, and now ultra. For most of those two years, I half-believed that quote myself.

Stock wasmtime serve + stock leptos_wasi worked great for portability and sandboxing, sure, but when you put it next to native Axum or ntex, it got smoked.

The turning point: wasm2c broke my mental model

The moment everything changed was when I experimented with compiling the guest through wasm2c and watched throughput jump massively.

Wait a second. If the same WebAssembly instructions compiled down to C could run that fast, then WebAssembly itself wasn't the bottleneck.

The bottleneck was everything around it: crossing the WASI host boundary 15 times per request, cabi_realloc thrashing, multi-threaded native abstractions dragged into a single-threaded guest, and Leptos SSR doing redundant work on every request.

I didn't want to give up the Wasm sandbox just to go fast the whole point of WASI is real isolation, portable components, and safe multi-tenant execution. So I asked a dumb question: what if we keep the full Wasmtime sandbox, keep real WASI component compatibility, and systematically kill every microsecond of overhead between the socket and the HTML?

This is NOT a "Hello World" benchmark

This is a real Leptos 0.8 full-stack app with everything people actually ship:

  • SSR (routed pages with <MetaTags/> and CSP nonces)
  • Islands + islands-router (partial hydration + client-side island navigation)
  • wasm-split (code-split island bundles + preload links)
  • Lazy loading & async resources
  • POST server functions (get_count, increment_count) + no-JS <form method="post"> redirect fallbacks
  • JSON API + static assets
  • Verified end-to-end in headless Chrome (hydration, split-wasm loading, islands-router nav, clicking counter buttons, no-JS SSR).

The Numbers (same machine, oha, median of 3 rotated rounds, req/s)

1 CPU (1 worker, c=16):

endpointaxumntexleptos_wasivs axumvs ntex
Static counter.js14,12810,23973,4005.20Γ—7.17Γ—
POST /api/increment_count51,94756,58955,6601.07Γ—0.98Γ—
POST /api/get_count60,51857,15366,1351.09Γ—1.16Γ—
Islands-router nav11,8739,72523,1291.95Γ—2.38Γ—
GET /api/hello (JSON)62,13764,34373,4931.18Γ—1.14Γ—
Counter page (SSR + island)7,8367,6641.70Γ—1.74Γ—
About page (SSR)12,12910,42822,2081.83Γ—2.13Γ—

Upfront caveats before the comment section lights me up:

  • Memory: Peak RSS is 70.3 MiB on 4 CPUs vs Axum's 13.1 MiB / ntex's 21.6 MiB (Wasmtime Cranelift JIT + per-worker linear memory isn't free).
  • Static files: counter.js is served from the host's in-memory --assets map before entering Wasm (vs ServeDir / ntex-files hitting the OS), so ignore that row if you only care about dynamic Rust execution β€” the SSR and POST server-function rows are the real story.
  • Still 100% sandboxed: The guest is a standard wasm32-wasip2 component running inside Wasmtime's linear memory sandbox β€” and the exact same .wasm binary still runs unmodified on stock wasmtime serve.

How we did it: every optimization (and what we threw away)

Every single optimization below was gated on reproducible 1-CPU and 4-CPU A/B benchmarks (3% regression gate on every endpoint; if an idea didn't show a clear win, we deleted it).

1. Killing the WASI host-call tax: 15 host calls β†’ 9 β†’ 0

Crossing guest↔host is where small WASI requests die.

  • Lazy wasi:http adapter (15 β†’ 9 calls on stock wasmtime serve**)**: Never fetch headers, scheme, or authority unless the handler actually reads them. One fields.from-list for response headers, skip set-status-code for 200, blocking-write-and-flush in 4 KiB chunks, and poll ready futures inside the guest with zero pollables.
  • Shared-memory Mailbox ABI v1 (9 β†’ 0 calls on GET/SSR): The guest exports a tiny #[repr(C)] struct (lean:mailbox). Our custom Wasmtime host writes the method + target straight into guest linear memory before calling handle, and reads status/headers/body pointers straight back out. Zero wasi:http calls, zero cabi_realloc re-entries. On stock wasmtime serve, the guest reads one word (state == 0) and falls back seamlessly to wasi:http.
  • Mailbox ABI v2 β€” inline request headers & body (POST: 8–9 calls β†’ 0): This was the last boss. Even after crushing Axum and ntex on SSR, POST /api/get_count and POST /api/increment_count sat at ~41–49k req/s because fields.entries triggered 1 + 2*H nested cabi_realloc.call_async re-entries (11–14 nested re-entries per POST!). Mailbox v2 adds independent 4 KiB request-header and 8 KiB request-body buffers with presence flags (if either overflows, only that half falls back to wasi:http, and v1 guests still work). islands-router header checks scan raw bytes without even allocating a HeaderMap. Result: get_count +47% (142k β†’ 209k on 4 CPUs), increment_count +51.5% (119k β†’ 181k).

2. Leaning into single-threaded Wasm (where native pays Arc/Mutex tax)

Native frameworks pay for Send + Sync, atomics, Arc<Mutex<...>>, Tokio work-stealing, and tower middleware layers on every request. wasm32 is single-threaded by construction with 32-bit pointers:

  • talc single-threaded allocator (replacing dlmalloc): Zero locking, much faster small-object alloc/free during SSR DOM rendering.
  • Wasm SIMD128 (-C target-feature=+simd128): Vectorized byte scanning, copies, and string operations in Wasmtime's Cranelift JIT.
  • Zero-alloc unused features: ResponseOptions is a thread-local handle allocated only when mutated (not Arc<Mutex<...>> per request), one reused waker per thread, route table built once per instance, process-wide redirect hook.

3. Fixing Leptos SSR hot paths (where the CPU actually went)

Once transport hit ~0 Β΅s, the profiler pointed straight at Leptos SSR itself:

  • One <head> scan instead of four: The app's <head> was ~13 KB, and stock leptos_meta + split-wasm preload injection + CSP nonce rewriting scanned it for </head> up to 4 times per request. Patched leptos_meta to insert at <!--HEAD--> and merged adapter edits into a single memchr::memmem pass: +24% on Counter, +32% on About.
  • Opt-in external, content-hashed HydrationScripts: Instead of re-emitting ~12 KB of inline islands bootstrap JS into every single HTML response (and scanning/copying it every request), serve it once at a content-hashed same-origin URL (/__leptos_hydration.<hash>.js) with immutable caching.
  • Patched leptos_router for SSR: Fast-path /path?query splitting without running the full url crate unless normalization is needed (was 12% of routed SSR), plain data for nested route params/matched paths instead of memos + signals + boxed loader futures per level, and splitting static vs reactive <A href=...> with Either so fixed links don't allocate closures or clone Strings.
  • Cached islands-router branch markers in tachys (format type name once per thread instead of allocating a String on every render).

4. What we tried and threw away

Half of performance work is deleting clever ideas that don't actually move the needle:

  • Caching converted response header lists (no gain)
  • Wasmtime pooling-allocator / custom guard sizes (within Β±5%)
  • Wasmtime -C inlining=y (actually made SSR slower: 62k β†’ 53k)
  • 8 worker threads on 4 CPUs (worse)
  • memchr::memmem in leptos_meta on top of SIMD128 (within noise)
  • Sailfish-style StreamBuilder capacity hints + memchr attribute escaping in tachys (within noise)

"Wait β€” couldn't Axum/ntex use the Leptos SSR patches too?"

Yes! And that's honestly the coolest part of this whole journey:

  1. Even on POST /api/get_count, POST /api/increment_count, and GET /api/hello β€” which touch none of leptos_router, leptos_meta, or HydrationScripts β€” sandboxed Wasm + Wasmtime is 1.07–1.45Γ— faster than native Axum and tied with or faster than native ntex.
  2. Most of our SSR patches (leptos_router static <A> & plain-data SSR routes, leptos_meta single-scan, external HydrationScripts) can be upstreamed to make native Leptos faster too.

Two years ago I was just trying to make leptos_wasi 0.1 compile and render a page. Seeing wasm2c proved Wasm wasn't inherently slow β€” and now ultra proves you don't even have to give up the Wasmtime sandbox to go toe-to-toe with (and beat) native Rust web stacks.

Repo: https://github.com/codeitlikemiley/leptos_wasi (ultra branch + PR #64 for mailbox v2; full methodology, browser tests, and raw CSVs in docs/optimizations.md and benchmarks/compare/).

Tear the benchmarks apart β€” I'll happily run any A/B or profile whatever you think I missed.