Consolidate Bolt PRs: optimize Context lock usage and eliminate redundant ContextValue clones#59
Conversation
…et_func/get_variable/value Agent-Logs-Url: https://github.com/ashyanSpada/expression_engine_rs/sessions/7e9ce6a0-1aa8-4510-9420-d73ff44eee82 Co-authored-by: ashyanSpada <22587148+ashyanSpada@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #59 +/- ##
==========================================
- Coverage 89.53% 89.35% -0.18%
==========================================
Files 11 11
Lines 1061 1062 +1
==========================================
- Hits 950 949 -1
- Misses 111 113 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Consolidates remaining Bolt optimizations by improving Context read-path performance and correctness around mutex lock scope during function evaluation.
Changes:
- Updated
get_func/get_variableto avoid cloning the fullContextValueenum when only one variant is needed. - Refactored
Context::value()to ensure the mutex guard is dropped before invoking stored functions (reducing contention and avoiding re-entrant deadlocks).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let func = { | ||
| let binding = self.0.lock().unwrap(); | ||
| match binding.get(name) { | ||
| Some(ContextValue::Variable(v)) => return Ok(v.clone()), | ||
| Some(ContextValue::Function(func)) => func.clone(), |
There was a problem hiding this comment.
Context::value now intentionally drops the MutexGuard before invoking a stored function (to avoid re-entrant deadlocks). Since this is a behavioral/concurrency fix, please add a regression test that would have deadlocked previously: store a function that calls back into the same Context (e.g., ctx.value("a")), call ctx.value("f") on another thread, and assert it completes via recv_timeout within a short duration.
21 overlapping AI-generated "⚡ Bolt:" PRs (#34–#57) targeting the same three areas (
Valuedisplay,Contextlocking, token string allocations) were clogging the PR queue. This consolidates the remaining valid improvements into a single clean change.Already on master (prior commit)
Value::fmtstreams directly tofmt::Formatterviawrite!— no intermediateStringbuffersDelimTokenType::as_str()returns&'static str;check_op()andtokenizer::expect()use it directlyThis PR:
src/context.rsget_func/get_variable— previously delegated toself.get()which calls.cloned()on the fullContextValueenum regardless of variant. Now acquires the lock directly and matches on a borrowed reference, cloning only the specific inner value when the variant matches:value()— explicit lock scope block ensuresMutexGuardis dropped before invoking any stored function, closing a potential deadlock window in reentrant contexts.Original prompt
Triage and Close Redundant AI-Generated "Bolt" Pull Requests
The repository currently has a large backlog of AI-generated pull requests (all prefixed with "⚡ Bolt:") that are clogging the PR queue and making it difficult to find genuine community contributions. These PRs span from #34 to #57 and all target overlapping concerns:
Valuedisplay allocations,Contextlock contention, and token string allocations.Task
Review all open "⚡ Bolt:" PRs and implement the best, non-overlapping performance improvements directly on the
masterbranch in a single, clean PR. This consolidates the valid work while eliminating the noise.The Bolt PRs to consolidate are:
.clone()sValueDisplay formattingWhat to implement
Read the source files (
src/value.rs,src/context.rs,src/token.rs,src/tokenizer.rs) and apply the best, correctness-preserving performance improvements from the Bolt PRs directly. Specifically:src/value.rs— Optimizefmt::DisplayforValueto write directly to the formatter instead of building intermediateStringallocations (e.g., avoidformat!(...).fmt(f)patterns).src/context.rs— Eliminate double-lookups in theContextmaps (e.g., useentry()API or singleget/insertcalls instead ofcontains_key+insert), and minimize Mutex lock duration by dropping the guard early where possible.src/token.rs/src/tokenizer.rs— Where token type comparisons build temporaryStrings just to compare, replace with&strslices or direct char/pattern comparisons to avoid heap allocations.Constraints
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Review this repo
Assistant: Here's a comprehensive review of ashyanSpada/expression_engine_rs — a pure Rust expression/rule engine library.
📊 At a Glance
0.7.0✅ Strengths
1. Clean, Well-Structured Codebase
The `...
This pull request was created from Copilot chat.