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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@
## 2023-11-09 - Dominator Analysis Optimization
**Learning:** In fixed-point iterative algorithms like the dominator tree analysis, using `Option<HashSet<T>>` and continuously allocating or cloning new sets (`new_dom = Some(pred_doms.clone())`, `all_blocks.clone()`) inside the inner loop is extremely expensive and produces O(N) intermediate allocations per block per iteration.
**Action:** Always pre-allocate a single mutable `HashSet` outside the loop, use `.clear()` each iteration, and compute in-place intersections using `.extend()` and `.retain()`. Also, use `.clone_from()` for updates to reuse existing capacity instead of reassignment.

## 2024-05-24 - Web Property Extraction Optimization
**Learning:** Extracting properties from the `RuntimeValue` DSL property lists in `stdlib/src/web/renderer.rs` and `stdlib/src/web/db.rs` was inefficient because the code called `.iter().find()` to resolve `text`, `id`, and `name` attributes, which creates unnecessary iterator overhead and closure allocation.
**Action:** Replace `.iter().find()` calls with a single-pass `for p in &dsl.properties` loop and `if` statements on the property names, stopping early when found, which significantly reduces execution overhead.
22 changes: 10 additions & 12 deletions stdlib/src/web/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,16 @@ pub fn init_sqlite_database(dsl: &DslBlockValue) {
if let Ok(conn) = open_connection() {
for child in &dsl.children {
if child.kind == "table" {
let table_name = child
.args
.first()
.map(|a| a.to_string())
.or_else(|| {
child
.properties
.iter()
.find(|p| p.name == "name" || p.name == "id")
.and_then(|p| p.value.as_ref().map(|v| v.to_string()))
})
.unwrap_or_else(|| "records".to_string());
let mut table_name = child.args.first().map(|a| a.to_string());
if table_name.is_none() {
for p in &child.properties {
if p.name == "name" || p.name == "id" {
table_name = p.value.as_ref().map(|v| v.to_string());
break;
}
}
}
let table_name = table_name.unwrap_or_else(|| "records".to_string());

let clean_name = sanitize_identifier(&table_name);
let create_sql = format!(
Expand Down
106 changes: 50 additions & 56 deletions stdlib/src/web/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,16 @@ pub fn render_card(html: &mut String, dsl: &DslBlockValue) {

pub fn render_heading(html: &mut String, dsl: &DslBlockValue) {
let mut id_attr = String::new();
let text = dsl
.args
.first()
.map(|a| a.to_string())
.or_else(|| {
dsl.properties
.iter()
.find(|p| p.name == "text")
.and_then(|p| p.value.as_ref().map(|v| v.to_string()))
})
.unwrap_or_else(|| "Heading".to_string());
let mut text = dsl.args.first().map(|a| a.to_string());
if text.is_none() {
for p in &dsl.properties {
if p.name == "text" {
text = p.value.as_ref().map(|v| v.to_string());
break;
}
}
}
let text = text.unwrap_or_else(|| "Heading".to_string());
for p in &dsl.properties {
if p.name == "id" {
if let Some(ref v) = p.value {
Expand All @@ -408,17 +407,16 @@ pub fn render_heading(html: &mut String, dsl: &DslBlockValue) {

pub fn render_text(html: &mut String, dsl: &DslBlockValue) {
let mut id_attr = String::new();
let text = dsl
.args
.first()
.map(|a| a.to_string())
.or_else(|| {
dsl.properties
.iter()
.find(|p| p.name == "text" || p.name == "content")
.and_then(|p| p.value.as_ref().map(|v| v.to_string()))
})
.unwrap_or_default();
let mut text = dsl.args.first().map(|a| a.to_string());
if text.is_none() {
for p in &dsl.properties {
if p.name == "text" || p.name == "content" {
text = p.value.as_ref().map(|v| v.to_string());
break;
}
}
}
let text = text.unwrap_or_default();
for p in &dsl.properties {
if p.name == "id" {
if let Some(ref v) = p.value {
Expand Down Expand Up @@ -1151,17 +1149,16 @@ pub fn render_custom_3d_studio(html: &mut String, _dsl: &DslBlockValue, id: &str
}

pub fn render_scene3d(html: &mut String, dsl: &DslBlockValue) {
let raw_scene_id = dsl
.args
.first()
.map(|a| a.to_string())
.or_else(|| {
dsl.properties
.iter()
.find(|p| p.name == "id")
.and_then(|p| p.value.as_ref().map(|v| v.to_string()))
})
.unwrap_or_else(|| "World".to_string());
let mut raw_scene_id = dsl.args.first().map(|a| a.to_string());
if raw_scene_id.is_none() {
for p in &dsl.properties {
if p.name == "id" {
raw_scene_id = p.value.as_ref().map(|v| v.to_string());
break;
}
}
}
let raw_scene_id = raw_scene_id.unwrap_or_else(|| "World".to_string());
let id = escape_html(&raw_scene_id);

let is_custom_studio = raw_scene_id.to_lowercase().contains("custom")
Expand Down Expand Up @@ -1837,18 +1834,16 @@ pub fn find_database_tables(blocks: &[RuntimeValue]) -> Vec<String> {
if dsl.kind == "database" {
for child in &dsl.children {
if child.kind == "table" {
let name = child
.args
.first()
.map(|a| a.to_string())
.or_else(|| {
child
.properties
.iter()
.find(|p| p.name == "name" || p.name == "id")
.and_then(|p| p.value.as_ref().map(|v| v.to_string()))
})
.unwrap_or_else(|| "records".to_string());
let mut name = child.args.first().map(|a| a.to_string());
if name.is_none() {
for p in &child.properties {
if p.name == "name" || p.name == "id" {
name = p.value.as_ref().map(|v| v.to_string());
break;
}
}
}
let name = name.unwrap_or_else(|| "records".to_string());
let clean = db::sanitize_identifier(&name);
if !tables.contains(&clean) {
tables.push(clean);
Expand Down Expand Up @@ -2076,17 +2071,16 @@ pub fn render_complete_document(
if !scenes_3d.is_empty() {
doc.push_str("<script>document.addEventListener('DOMContentLoaded', () => {");
for sc in &scenes_3d {
let sc_id = sc
.args
.first()
.map(|a| a.to_string())
.or_else(|| {
sc.properties
.iter()
.find(|p| p.name == "id")
.and_then(|p| p.value.as_ref().map(|v| v.to_string()))
})
.unwrap_or_else(|| "World".to_string());
let mut sc_id = sc.args.first().map(|a| a.to_string());
if sc_id.is_none() {
for p in &sc.properties {
if p.name == "id" {
sc_id = p.value.as_ref().map(|v| v.to_string());
break;
}
}
}
let sc_id = sc_id.unwrap_or_else(|| "World".to_string());

let mut initial_geo = "scifi".to_string();
let mut initial_color = "cyan".to_string();
Expand Down
Loading