You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf(context): optimize Context map lookups to reduce lock contention and cloning
- Replaces double HashMap lookups with a single `.get().cloned()` call.
- Uses pattern matching in `value()`, `get_func()`, and `get_variable()` to directly handle the cloned `ContextValue` variant without redundant `clone()` invocations on the inner types.
- Crucially, allows the Mutex lock to be dropped earlier in `value()` before executing arbitrary long-running inner function closures.
Co-authored-by: ashyanSpada <22587148+ashyanSpada@users.noreply.github.com>
**Learning:** In highly accessed global state structures like `Context`, redundantly cloning the encapsulated `ContextValue` struct and its underlying inner values inside lock blocks leads to measurable overhead and unnecessary allocations. Further, double hash map lookups where we check if a key exists then immediately unwrap it again, can be simply avoided using pattern matching.
3
+
**Action:** Use single `.get()` calls over hash maps followed by `.cloned()`. Pattern match directly on the result to avoid redundant hash map operations. Ensure locks are dropped before executing potentially long-running functions.
0 commit comments