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 @@ -20,3 +20,6 @@
## 2024-08-01 - Bytecode Disassembler String Allocation Optimization
**Learning:** Formatting directly into a string buffer inside a tight loop with `write!(buffer, ...)` avoids unnecessary string heap allocations compared to `buffer.push_str(&format!(...))`.
**Action:** Always prefer formatting directly into the target String buffer when concatenating strings in loops in performance-sensitive paths like debuggers or disassemblers.
## 2024-05-24 - Optimize rusqlite extraction in query_map
**Learning:** When mapping `rusqlite` query results to dynamic types like `IndexMap<String, RuntimeValue>` in `techscript_stdlib`, use `row.get_ref_unwrap(i)` to map the underlying `rusqlite::types::ValueRef` directly to the corresponding `RuntimeValue` (e.g., `Int`, `Float`, `Str`), avoiding the overhead and type issues of coercing all numeric and null columns to `String`s.
**Action:** When extracting data from rusqlite database rows, inspect the `ValueRef` directly with `get_ref` or `get_ref_unwrap` instead of eagerly copying out a target Rust type like `String`, significantly reducing allocations and retaining correct native types for numeric and null data.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions stdlib/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl StdlibRegistry {
.query_map(rusqlite::params_from_iter(params), |row| {
let mut map = IndexMap::with_capacity(col_count);
for i in 0..col_count {
let val = row.get_ref(i)?;
let val = row.get_ref_unwrap(i);
let rt_val = match val {
rusqlite::types::ValueRef::Null => RuntimeValue::Null,
rusqlite::types::ValueRef::Integer(v) => {
Expand All @@ -194,11 +194,9 @@ impl StdlibRegistry {
rusqlite::types::ValueRef::Real(v) => {
RuntimeValue::Float(v)
}
rusqlite::types::ValueRef::Text(v) => {
RuntimeValue::Str(
String::from_utf8_lossy(v).into_owned(),
)
}
rusqlite::types::ValueRef::Text(v) => RuntimeValue::Str(
std::str::from_utf8(v).unwrap_or_default().to_string(),
),
rusqlite::types::ValueRef::Blob(v) => {
RuntimeValue::Str(
String::from_utf8_lossy(v).into_owned(),
Expand Down
Loading