Skip to content

perf: deduplicate wildcard patterns before expanding events - #13522

Merged
loks0n merged 1 commit into
mainfrom
codex/optimize-event-expansion
Sep 8, 2026
Merged

loks0n merged 1 commit into
mainfrom
codex/optimize-event-expansion

Conversation

@loks0n

@loks0n loks0n commented Sep 8, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Database event expansion repeatedly builds identical wildcard combinations, substitutes every parameter into each copy, and only then discards duplicates. Deduplicate intermediate wildcard patterns before substitution and replace repeated parameter-name filtering with equivalent direct substitutions. Preserve concrete-event-first ordering, wildcard and parent event order, database aliases, and numeric-key behavior.

This path appeared in both API shutdown and realtime delivery during live Cloud sampling with php-fast-profile. It accounted for 90 samples, or 3.48% after excluding scheduler/start leaf samples. These are wall-clock PHP stack samples, not on-CPU measurements.

Local PHP 8.5.9 benchmark: median of seven alternating before/after rounds, 5,000 calls per round:

Event expansion Before After Reduction
Three-level database event with legacy aliases 411.27 ms 151.25 ms 63.2%
Three-level documentsdb event 385.25 ms 110.38 ms 71.3%

These improvements apply to event expansion, not total pod CPU. No production change has been deployed.

Test Plan

  • Added an exact ordered-event regression, including the concrete first event used to derive the realtime target.
  • Event unit directory on current main plus this patch: 13 tests, 278 assertions passed. Used PHP 8.5.9, existing local dependencies, and the current local queue package to supply main's new Synchronous interface.
  • Pint passed for both changed files; git diff --check passed.
  • 3,000 differential cases matched the original output exactly, including ordering: parameter permutations, extra/numeric parameters, wildcard/empty/overlapping values, and legacy/tablesdb/documentsdb/vectorsdb contexts.
  • Compatibility tests pass both implementations; the before/after benchmark demonstrates the performance improvement.
  • No E2E or production rollout validation was run for this local string-generation change.

Related PRs and Issues

Cloud consumes this shared implementation through appwrite/server-ce and will need a dependency update after merge.

Checklist

  • Read the contributing guidelines.
  • No API metadata changes; generated specs and example docs are unchanged.

@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR optimizes event-name expansion by deduplicating intermediate wildcard patterns before parameter substitution while preserving the existing event contract.

  • Replaces repeated parameter-key filtering and immediate expansion with an insertion-ordered wildcard set.
  • Preserves concrete-event-first ordering, parent-event ordering, database aliases, and final deduplication.
  • Adds an exact ordered regression test for a three-level DocumentsDB event.

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness, security, or repository-rule issues identified.

The optimized expansion retains the concrete event first and preserves the same ordered set of wildcard and parent events used by realtime, function, and webhook subscription matching.

Important Files Changed

Filename Overview
src/Appwrite/Event/Event.php Deduplicates intermediate wildcard patterns before value substitution without changing the generated event set or first-occurrence order.
tests/unit/Event/EventTest.php Adds an exact regression assertion covering concrete, wildcard, and parent event delivery order.

Reviews (1): Last reviewed commit: "perf: deduplicate wildcard patterns befo..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → codex/optimize-event-expansion (after).

Metric Before After Change
🚀 Requests/sec 400.59 421.74 🟢 +5.3%
⏱️ Latency P50 44.36 ms 41.03 ms 🟢 -7.5%
⏱️ Latency P95 99.38 ms 96.83 ms ⚪ -2.6%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 41.03 96.83 25,992 421.74 -2.56
Account 80.61 147.4 1,368 22.77 -1.83
TablesDB 39.36 70.31 14,136 232.06 -8.32
Storage 38.3 85.75 6,840 113.82 -1.75
Functions 64.68 115.86 3,648 61.24 -3.77

Top API waits (after)

API request Max wait (ms)
functions.variables.delete 287.41
account.name.update 245.87
tablesdb.rows.create 231.23
functions.variables.update 201.68
functions.variables.create 192.46

@loks0n
loks0n merged commit 33b5a7b into main Sep 8, 2026
46 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 10, 2026
2 of 4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants