mirror of
https://github.com/element-hq/synapse.git
synced 2026-11-04 11:17:51 +00:00
Validating a power levels event against its JSON schema took 250 us even with the validator compiled once, ten times the rest of `validate_new`. Rust now answers "certainly valid" or "not sure" for the power levels schema, the mentions schema and the canonical JSON check. Python runs its own check only when Rust is not sure, so Python still decides every rejection and its error message. Rust only accepts integers it parsed as `i64` in range, so floats such as `50.0`, which the schema accepts, are left to Python. `_check_size_limits` takes the canonical JSON length from Rust instead of building the dict and encoding it. Rust keeps each number's source text, which can differ from how Python prints a float, so an event with any number other than a plain integer is still measured in Python. `validate_new` on a default power levels event: 305 us before, 43 us after. Tests generate random contents and check that whatever Rust accepts, Python accepts too. They found that the strict canonical serializer in `canonical_json.rs` does not range-check numbers inside arrays, so the canonical check walks the JSON itself. Nothing else uses strict mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PVLsNh6akt4ifEizY4D1ta