Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
## 2024-05-18 - Removed redundant clone of VM stack during trace logs
**Learning:** In `runtime/vm/src/executor.rs`, the debugging instruction trace `self.debugger.trace_instruction` was cloning the entire VM stack using `&self.stack.get_dump()` for every single instruction executed. This caused significant `O(N)` overhead inside the main fetch-decode-execute loop just to format debug output. A new `data_slice()` method was added to `ValueStack` to provide zero-copy slice access (`&[RuntimeValue]`) instead, completely eliminating the allocation overhead.
**Action:** Always scrutinize deep clones in logging, tracing, or hot path loops. Use slice references (`&[T]`) instead of `Vec::clone` when the caller only needs read-only access to a collection.
## 2024-06-25 - Suboptimal Line Search in LSP
**Learning:** Using `chars().nth()` with a byte offset (such as one returned by `.find()`) inside a loop over a string creates an O(N) penalty and may result in an incorrect character lookup if multi-byte unicode characters are present.
**Action:** Use string slicing with the byte index to create a subset string slice, and call `.chars().next_back()` or `.chars().next()` on it for an O(1) and UTF-8 safe boundary lookup.
8 changes: 4 additions & 4 deletions tools/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,11 @@ impl LanguageServer for Backend {
while let Some(pos_in_line) = line[start_pos..].find(&word) {
let actual_pos = start_pos + pos_in_line;
let char_before = if actual_pos > 0 {
line.chars().nth(actual_pos - 1)
line[..actual_pos].chars().next_back()
} else {
None
};
let char_after = line.chars().nth(actual_pos + word_len);
let char_after = line[actual_pos + word_len..].chars().next();

let is_boundary_before =
char_before.map_or(true, |c| !c.is_alphanumeric() && c != '_');
Expand Down Expand Up @@ -803,11 +803,11 @@ impl LanguageServer for Backend {
while let Some(pos_in_line) = line[start_pos..].find(&word) {
let actual_pos = start_pos + pos_in_line;
let char_before = if actual_pos > 0 {
line.chars().nth(actual_pos - 1)
line[..actual_pos].chars().next_back()
} else {
None
};
let char_after = line.chars().nth(actual_pos + word_len);
let char_after = line[actual_pos + word_len..].chars().next();

let is_boundary_before =
char_before.map_or(true, |c| !c.is_alphanumeric() && c != '_');
Expand Down
Loading