Use more `Arc`s internally
aumetra opened this issue · comments
Each service should optimally be Arc
'd. Each extraction via axum
state extractors clones the entire service, which we really don't need to do since all the methods only require immutable references anyway.
To decrease the overall memory usage of the Arc
s, we can use the triomphe
crate, which provides Arc
s without weak references, decreasing the size by one machine word (and avoiding some atomic operations each clone/drop)
All in all, we can just use the #[builder(into = triomphe::Arc<WhateverService>)]
annotation to output already Arc
'd services.
Also this isn't really a performance degradation since the heap allocations are all performed at start-up, then never again.
These allocations also don't use dynamic dispatch, therefore the runtime performance is equal to their stack allocated counterparts.