Skip to content

Split routes by verb during compilation#6739

Open
josevalim wants to merge 5 commits into
mainfrom
jv-router-split
Open

Split routes by verb during compilation#6739
josevalim wants to merge 5 commits into
mainfrom
jv-router-split

Conversation

@josevalim

@josevalim josevalim commented Jun 29, 2026

Copy link
Copy Markdown
Member

This pull request groups compiled routes by verb, which speeds up compilation times for large routers up to 3x. A side-effect is that match/forward routes are always matched last.

Therefore, this pull request changes the semantics of dead routes. If you had this code:

match "/foo"
get "/foo"

The second route would never be matched but it is now as part of this pull request. However, get "/foo" should not be there in the first place. It is effectively a dead route.

Currently WIP. We should either document this pitfall or put this change behind an option. I am fine with documenting this in the CHANGELOG as the code above should either not exist or be correct anyway.

@SteffenDE

Copy link
Copy Markdown
Member

I think it's fine to just mention it in the changelog. Alternatively, maybe we could detect such dead routes at compile time and drop them to keep the same behavior, emitting a deprecation warning? Then we drop that extra code for 2.0.

This pull request compiles routes by verb, which speeds up
compilation times for large routes. This is done by making
sure `match/forward` statements always come last.

Therefore, this pull request changes the semantics of *dead
routes*. If you had this code:

    match "/foo"
    get "/foo"

The second route would never be matched but it is now as part
of this pull request. However, `get "/foo"` should not be there
in the first place. So the routes should either be rearranged
or removed anyway.
Comment thread CHANGELOG.md Outdated
assert conn.resp_body == "users move"
end

test "any verb matches" do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did we remove that test?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a match :* above which is tested through other paths and this was emitting a warning with the new changes, so I moved it to a separate warning test!

josevalim and others added 2 commits June 29, 2026 21:23
Co-authored-by: Steffen Deusch <steffen@deusch.me>
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