You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update the style guide with a focus on super-performance, readability,
and a stricter blocking policy. This includes detailed guidance on
instrumentation, performance, and code clarity.
> TL;DR: Treat performance as a feature. Prefer zero/low‑overhead code paths, avoid accidental allocations, and never pay logging costs on hot paths unless explicitly gated.
4
+
> TL;DR: Treat performance as a feature**and** clarity as a constraint. We ship **super-performant code** that is easy to read, easy to change, and hard to misuse. Prefer zero/low-overhead paths, avoid accidental allocations, and never pay logging costs on hot paths unless explicitly gated. Keep control flow shallow and intent obvious.
4
5
5
6
---
6
7
7
8
## Quick Facts (Tracing Semantics You Must Know)
8
9
9
10
-**Default `#[instrument]` level is `debug`.**
10
11
- Tracing levels are ordered: `error > warn > info > debug > trace`. Enabling `info`**does not** enable `debug`.
11
-
-**Field expressions inside `#[instrument(... fields(...))]` are evaluated at function entry** (macro expansion time for that call site), before any subscriber decides to record or drop the span. If those expressions do heavy work (e.g., `pretty_print`, `format!`, `to_string`, serialization), you **pay that cost** regardless of whether the span is ultimately recorded.
12
-
- Therefore, any non‑trivial work inside `fields(...)` is a foot‑gun even when you think "it's only at `debug`."
12
+
-**Field expressions inside `#[instrument(... fields(...))]` are evaluated at function entry** (before any subscriber decides to record or drop the span). If those expressions do heavy work (e.g., `pretty_print`, `format!`, `to_string`, serialization), you **pay that cost** regardless of whether the span is recorded.
13
+
- Therefore, any non-trivial work inside `fields(...)` is a foot-gun even when you think “it’s only at `debug`.”
13
14
14
15
---
15
16
16
-
## Blocking Policy (exact)
17
+
## Super-Performance Ethos
17
18
18
-
Gemini must **request changes (block the PR)** when any of the following appear:
19
+
-**Zero-cost baseline:** When disabled, observability adds ~0 runtime cost.
20
+
-**Hot-path budget ≈ near-zero:** Guard everything non-trivial, minimize allocs, avoid dynamic dispatch and stringification in loops, keep data on the stack/arenas/Bytes where possible.
21
+
-**Measure, don’t guess:** PRs that plausibly affect p95/p99 latency or memory should include micro-benchmarks or before/after numbers.
22
+
-**Prefer predictable memory:** Borrow over own, interning for high-cardinality strings, `SmallVec/ArrayVec` where sizes are bounded, arena/bump alloc for structured lifetimes.
19
23
20
-
-**A. `#[tracing::instrument]` uses the default level (`info`) on hot paths.**
21
-
`info` spans are commonly enabled in production. Span creation + any eager field evaluation will run on hot paths. Use `level = "trace"` for hot code and record richer details lazily (see patterns below) when a higher level is actually enabled.
24
+
---
22
25
23
-
-**B. `#[tracing::instrument]` uses `level = "debug"` (or higher verbosity) and either condition holds:**
Even if the runtime filter disables that `debug` span, those field expressions are still evaluated at function entry - wasted work.
26
+
## Blocking Policy (exact)
27
27
28
-
-**C. Any heavy work is performed just to log/trace on a hot path**without a guard (e.g., `tracing::enabled!` or a feature flag).
28
+
Gemini must **request changes (block the PR)**when any of the following appear:
29
29
30
-
> **Baseline for hot paths:**`#[instrument(skip_all, level = "trace", fields(... cheap only ...))]` + gated/lazy recording for anything expensive or no instrumentation at all.
30
+
### Tracing / Instrumentation
31
+
-**A. `#[instrument]` at `level = "info"` (or higher) on hot paths.**
32
+
`info` is commonly enabled in prod; span creation + eager field eval will run in hot code. Use `level = "trace"` on hot paths and record richer details lazily when enabled.
33
+
-**B. `#[instrument]` at `debug` (default) on hot paths without `skip_all`, or with computed fields.**
34
+
Even if disabled at runtime, `fields(...)` are evaluated. Require `skip_all` and **cheap fields only**.
35
+
-**C. Any heavy work is performed just to log/trace on a hot path** without a guard (`tracing::enabled!`, feature flag, or config knob).
36
+
37
+
> **Hot-path baseline:**
38
+
> `#[instrument(skip_all, level = "trace", fields(... cheap only ...))]` + gated/lazy recording for anything expensive, or no instrumentation.
39
+
40
+
### Readability / Simplicity
41
+
-**D. Deeply nested control flow** (more than **2 levels** on hot paths, **3** elsewhere) when it can be flattened with guard clauses, early returns, or `match`.
42
+
-**E. Large monolithic functions** (> ~80 lines, or doing multiple responsibilities) when they can be split into focused helpers.
43
+
-**F. Clever/opaque iterator chains** that obscure intent or allocate inadvertently; prefer a clear `for` loop or smaller helpers.
44
+
-**G. Non-idiomatic error handling:**`unwrap/expect` in non-test code (except proven cold init/CLI); missing context on propagated errors where it matters.
45
+
-**H. Naming that hides intent:** cryptic abbreviations, misleading words, type-hiding via wild generics without good reason.
46
+
-**I. Unbounded growth patterns:** maps/vectors with unbounded cardinality in hot paths without explicit caps/eviction.
47
+
-**J. Unsafe without proof:**`unsafe` blocks without precise safety comments, tests, or measurable wins.
31
48
32
49
---
33
50
34
51
## Goals
35
52
36
-
-**Always review PRs through a performance lens.**
37
-
-**Block**changes that add avoidable runtime overhead (allocations, stringification, extra clones, unnecessary async/await boundaries, unbounded maps/vecs, etc.).
38
-
-**Strict rules for `tracing`**so instrumentation doesn't silently tax hot paths.
39
-
-**Review PRs through a "best-practices in Rust" lens.**
- Truly **cold** admin/maintenance paths (schema reload, health checks, CLI tools) **may** use `level = "info"` with **cheap** fields only.
193
-
- Still **avoid** expensive field computation in attributes; prefer gated record.
194
-
195
-
---
196
-
197
-
## Rationale (why we're strict)
198
-
199
-
-`#[instrument]`**creates spans** and **evaluates its `fields(...)`** at function entry. With the default `info` level, this happens under typical production filters; with `debug`, the field expressions are still evaluated even if the span is dropped later.
200
-
- Stringification/pretty printing can dominate latency on tight loops; a handful of these across hot paths quickly becomes a measurable tax.
201
-
- The safe baseline (`skip_all`, `level="trace"`, gated recording) keeps the lights on without sacrificing debuggability when you need it.
202
-
203
-
---
204
-
205
-
## PR Author Checklist (pre‑submit)
206
-
207
-
-[ ] No default/`info`/`debug``#[instrument]` on hot paths unless justified and still `skip_all` + cheap fields only.
208
-
-[ ] Every `#[instrument]` has `skip_all`.
209
-
-[ ] No function calls/allocs in `fields(...)`.
210
-
-[ ] Hot‑path logs/metrics are gated or relocated.
0 commit comments