Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

perf(routing): replace recursion in favor of iteration #705

Merged
merged 1 commit into from
Nov 9, 2024

Conversation

blackshadev
Copy link
Contributor

What

Refactor the adding of routes to the routing tree by replacing recursion with iteration.

Recursion is pretty inefficient in PHP. This relatively small refactor is roughly 10% faster

Benchmarks

This branch

+------------------------+-----------------------------------------+-----+------+-----+----------+---------+--------+
| benchmark              | subject                                 | set | revs | its | mem_peak | mode    | rstdev |
+------------------------+-----------------------------------------+-----+------+-----+----------+---------+--------+
| RouteConfiguratorBench | benchRouteConfigConstructionRouteAdding |     | 1000 | 5   | 2.100mb  | 1.016ms | ±0.32% |
+------------------------+-----------------------------------------+-----+------+-----+----------+---------+--------+

Main

+------------------------+-----------------------------------------+-----+------+-----+----------+---------+--------+
| benchmark              | subject                                 | set | revs | its | mem_peak | mode    | rstdev |
+------------------------+-----------------------------------------+-----+------+-----+----------+---------+--------+
| RouteConfiguratorBench | benchRouteConfigConstructionRouteAdding |     | 1000 | 5   | 2.101mb  | 1.101ms | ±0.94% |
+------------------------+-----------------------------------------+-----+------+-----+----------+---------+--------+

@innocenzi innocenzi changed the title refactor(routing): replace recursion in favor of iteration perf(routing): replace recursion in favor of iteration Nov 9, 2024
@brendt brendt merged commit 32aaff4 into tempestphp:main Nov 9, 2024
58 checks passed
@brendt
Copy link
Member

brendt commented Nov 9, 2024

Nice! You're on a roll @blackshadev 🌊

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants