Skip to content

perf(container): cap the dependency chain backtrace - #2273

Open
osbre wants to merge 1 commit into
tempestphp:3.xfrom
osbre:perf/container-backtrace-limit
Open

perf(container): cap the dependency chain backtrace#2273
osbre wants to merge 1 commit into
tempestphp:3.xfrom
osbre:perf/container-backtrace-limit

Conversation

@osbre

@osbre osbre commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

resolveChain() previously captured the entire call stack on every container resolution but only needed the immediate caller's frame.

Added a test covering the reported origin file, which lacked coverage previously.

Impact

Micro-optimization territory 😄

  • Container lookups: Changes performance from linear to constant relative to stack depth, dropping from 3.23 µs down to 1.43 µs at depth 60.
  • App performance: Saves about 35 µs per request on a trivial route. On an application doing real-world work it's a tiny fraction of a percent, but it's a tidy way to remove unnecessary overhead.

@osbre
osbre requested a review from brendt as a code owner September 5, 2026 02:45
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Benchmark Results

Comparison of perf/container-backtrace-limit against 3.x (cf035264805564eb789f2741734e481aa3696b4d).

Open to see the benchmark results
Benchmark Set Mem. Peak Time Variability
QueryExecutionBench(benchExecuteInsert) - 4.400mb 0.00% 9.120μs -6.78% ±1.78% +31.69%
GenericRouterBench(benchDispatch) Static route 5.264mb 0.00% 40.799μs -7.76% ±0.47% -9.36%
GenericRouterBench(benchDispatch) Dynamic route 5.268mb 0.00% 48.127μs -7.37% ±0.50% -1.98%
GenericRouterBench(benchDispatch) Dynamic short 5.268mb 0.00% 48.358μs -6.28% ±0.72% +162.19%
GenericRouterBench(benchDispatchWithoutMiddleware) Static route 5.263mb 0.00% 33.820μs -5.82% ±0.46% +5.33%
ViewRenderBench(benchPlainHtml) - 22.035mb 0.00% 421.681μs -7.79% ±1.79% -33.05%
ViewRenderBench(benchControlFlow) - 44.501mb 0.00% 639.534μs -5.41% ±1.71% +55.27%
DiscoveryScanBench(benchFullDiscoveryScan) - 25.857mb 0.00% 20.479ms +7.16% ±1.16% +9.58%

Generated by phpbench against commit f39b24c

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.

1 participant