GithubHelp home page GithubHelp logo

Route: cache vs lazy load about core HOT 7 CLOSED

kohana avatar kohana commented on July 17, 2024
Route: cache vs lazy load

from core.

Comments (7)

acoulton avatar acoulton commented on July 17, 2024

Interesting proposal, could you explain why this (especially dropping caching) would be better?

from core.

WinterSilence avatar WinterSilence commented on July 17, 2024

Both versions work at same speed:
current - spends time on deserialization, problems with serialization closures
my - spends time on generation of regexp (it need not for all routes, in most cases, for 2-5 objects), removes external dependence (Kohana_Core).

from core.

acoulton avatar acoulton commented on July 17, 2024

Do you have profiling to support that?

It must depend on pattern of site usage and order of route definitions. If most requests are to the last defined route, then all routes will have to be compiled every request.

We use a reasonable number of routes in our project and there's a very noticeable boost from using Route::cache so would want to be sure of the impact before dropping it.

Accept the point re serialising closures. Dependency on Kohana_Core could be removed by injection if necessary.

Maybe the solution is to add lazy load but keep Route::cache so people can choose which works best for them?

from core.

WinterSilence avatar WinterSilence commented on July 17, 2024

Do you have profiling to support that?

Ok, add tests tomorrow.

Maybe the solution is to add lazy load but keep Route::cache so people can choose which works best for them?

These versions are not compatible (

from core.

WinterSilence avatar WinterSilence commented on July 17, 2024

We use a reasonable number of routes in our project and there's a very noticeable boost from using Route::cache so would want to be sure of the impact before dropping it.

For example, we have 9 routes (50-60% requests) and default route (40-50% requests), then regexp compile not for all routes in 50-60% cases. Current code deserialize routes in 100% requests.

from core.

acoulton avatar acoulton commented on July 17, 2024

We use a reasonable number of routes in our project and there's a very noticeable boost from using Route::cache so would want to be sure of the impact before dropping it.

For example, we have 9 routes (50-60% requests) and default route (40-50% requests), then regexp compile not for all routes in 50-60% cases. Current code deserialize routes in 100% requests.

But do you have profiling showing overhead of deserialize compared to overhead of compiling? I've not noticed an issue with deserialize in production. They're relatively small objects.

Your example slightly simplifies when you say "regexp compile not for all routes in 50-60% of cases". There'll be a percentage that compile 8/9 routes, some do 7/9, some do 6/9 etc.

Say for ease you have 100 requests a minute and traffic like this:

Route req/min compiles/min
1 9 9
2 9 18
3 9 27
4 9 36
5 9 45
6 9 54
7 9 63
8 9 72
9 9 81
default 46 460
total 100 865

With Route::cache you'd have 100 deserialize operations. With lazy load you have 865 compile operations. Is deserializing really more than 8 times slower than compiling?

Obviously like I said it depends on your traffic pattern and route definitions. Still though I think this isn't a change we should make on a hunch, you need to provide data showing the relative performance.

Maybe the solution is to add lazy load but keep Route::cache so people can choose which works best for them?

These versions are not compatible

Why? Surely if Route::cache forces all routes to compile then they can be cached, or am I missing something?

IMO unless you have profiling data we should close this. If you want to add lazy load that supports caching, then that would give people a useful choice eg if they want to use closures in filters.

from core.

WinterSilence avatar WinterSilence commented on July 17, 2024

Why? Surely if Route::cache forces all routes to compile then they can be cached, or am I missing something?

Some cached routes contain not compiled regexp - need cache only compiled routes or recache if routes added\compiled.

In order to avoid problems with serialization can add a parameter $cache to route - if we add closure to filters, then set $cache = false and before caching routes we check this parameter.

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.