mezzio / mezzio-router

Router subcomponent for Mezzio
https://docs.mezzio.dev/mezzio/features/router/intro/
BSD 3-Clause "New" or "Revised" License
24 stars 13 forks source link

Optimize route addition #1

Closed weierophinney closed 3 years ago

weierophinney commented 4 years ago

This pr optimizes route addition by removing O(n) duplicate check. In case of big monolitic application this starts to bite performance of application initialization. By the way i have added test for documented feature of detecting duplicate names, it was failing on develop branch.


Originally posted by @nightlinus at https://github.com/zendframework/zend-expressive-router/pull/78

weierophinney commented 4 years ago

It seems like we fixed requested changes, am i missing something?


Originally posted by @nightlinus at https://github.com/zendframework/zend-expressive-router/pull/78#issuecomment-442027674

weierophinney commented 4 years ago

Have this as some type of property test RouteCollectorTest::testCreatingHttpRouteWithExistingPathShouldBeLinear it took 320ms vs 5s 940ms with new and old implementation on my machine.


Originally posted by @nightlinus at https://github.com/zendframework/zend-expressive-router/pull/78#issuecomment-442404580

weierophinney commented 4 years ago

I extract duplicate checks and storage logic to separate class, it looks better to me.


Originally posted by @nightlinus at https://github.com/zendframework/zend-expressive-router/pull/78#issuecomment-442564267

10n commented 4 years ago

An idea would be to check for duplicates only in development mode ( $container->get('config')['debug'] ) ?