Why Nostr? What is Njump?
2024-02-17 14:07:24
in reply to

Mo :ferris: :tux: on Nostr: npub1nh9ll…sp2mr Arc of a trait object is inefficient 😅 When working with a web ...

Arc of a trait object is inefficient 😅

When working with a web server state, you normally create the state and don't drop it until it is dropped automatically at the end of the program. Therefore, I prefer to bypass using an Arc by intentionally "leaking" the state. Here is an example:

https://codeberg.org/mo8it/oxitraffic/src/commit/8f26a82301937bbdbe383622fe3d15d99f368b79/src/app.rs#L28

You wrap the state in a Box and leak that Box to get a static reference &'static State

This avoids the atomic incrementation in the reference counter.
Author Public Key
npub1j7fc87rk03whjh72mphc9hrm8zecfsdywdcscsesznwzcrasudvs75mapy