Skip to content

Make Router faster to clone - #1123

Merged
davidpdrsn merged 5 commits into
mainfrom
faster-router-clone
Jun 27, 2022
Merged

Make Router faster to clone#1123
davidpdrsn merged 5 commits into
mainfrom
faster-router-clone

Conversation

@davidpdrsn

Copy link
Copy Markdown
Member

Motivation

Router is cloned once for every request in IntoMakeService::call so ideally it should be cheap to do so.

Solution

Wrap the Node in a Arc and rebuild it when calling Router::router. This is fine since it only happens during startup.

I did a simple benchmark where I cloned a Router with 1000 routes and this brought the time down from 176.916µs to 92.698µs. So almost 50% 📈

I also attempted to Arc the other fields but since they're !Sync the Arc becomes !Send which is a no-go. Using SyncWrapper doesn't help as that requires exclusive access which we cannot get through an Arc.

@davidpdrsn
davidpdrsn requested a review from jplatte June 26, 2022 21:03
@davidpdrsn
davidpdrsn enabled auto-merge (squash) June 26, 2022 21:05
Comment thread axum/src/routing/mod.rs Outdated
davidpdrsn and others added 2 commits June 27, 2022 10:11
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Comment thread axum/src/routing/mod.rs Outdated
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
@davidpdrsn
davidpdrsn disabled auto-merge June 27, 2022 09:00
@davidpdrsn
davidpdrsn merged commit cb20747 into main Jun 27, 2022
@davidpdrsn
davidpdrsn deleted the faster-router-clone branch June 27, 2022 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants