Repository navigation
Conversation
…changed Profiling the cloud API showed json_decode as the top leaf function (10.5% of busy CPU): collection metadata, the project and the user are read from Redis on every request and decoded every time, although the stored string almost never changes between requests. The Redis and multiplexing adapters now keep a small per-process memo of decoded envelopes keyed by cache key. Redis stays the source of truth: every load still fetches the string, and the decoded value is reused only while the string is byte-for-byte the one it was decoded from, so a purge or a save from any process is seen on the next load. The memo holds 128 keys, evicts the oldest, skips payloads under 1 KB, and re-applies the envelope TTL on every hit. Measured on a 9 KB collection metadata envelope from a local Redis (5k iterations, PHP 8.5): a cache load costs 57 µs CPU before and 15 µs after with telemetry off; the string compare on a hit is within noise of the bare HGET. Through Database::getCollection that is 92 µs to 56 µs. Refs appwrite-labs/cloud#5861. Co-Authored-By: Claude Fable 5.1 <[email protected]>
loks0n
requested review from
Meldiron,
abnegate and
eldadfux
as code owners
September 16, 2026 09:08
This was referenced Sep 24, 2026
Member
|
packages/cache now lives in appwrite/appwrite; ported as appwrite/appwrite#13915. Thanks! |
30 of 34 tasks
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Profiling the cloud API (appwrite-labs/cloud#5861) showed
json_decodeas the top leaf function at 10.5% of busy CPU. Collection metadata, the project and the user are read from Redis on every request and their JSON decoded every time, although the stored string almost never changes between requests.What
The Redis and multiplexing adapters keep a small per-process memo of decoded envelopes keyed by cache key (
DecodedEnvelopes). Redis stays the source of truth: every load still fetches the string, and the decoded value is reused only while the string is byte-for-byte the one it was decoded from. A purge or a save from any process changes the string and the next load decodes again, so the memo cannot serve anything Redis would not.Envelope::unwrap()is split out ofEnvelope::decode()so the memo can keep the envelope time.Measured
Warm cache, 9 KB collection metadata envelope from a local Redis, PHP 8.5, 5k iterations, CPU µs per operation:
Cache::load(telemetry off)Cache::load(OpenTelemetry on)Database::getCollection(telemetry off)Database::getDocument(OpenTelemetry on)The string compare on a hit is within noise of the bare
HGET(10.4 vs 10.3 µs). The OpenTelemetry rows include #280 (breaker gauges observed at collect, no exemplars); the telemetry-off rows isolate this change.Memory: a memoized 9 KB envelope holds the string plus its decoded array, so the bound is roughly 128 × (payload + decoded size) per adapter instance, per worker process.
🤖 Generated with Claude Code