Skip to content

⚡ perf(eval): wrap function parameters and Markdown in Box for improved memory management#1703

Merged
harehare merged 5 commits into
mainfrom
perf/wrap-in-box
May 8, 2026
Merged

⚡ perf(eval): wrap function parameters and Markdown in Box for improved memory management#1703
harehare merged 5 commits into
mainfrom
perf/wrap-in-box

Conversation

@harehare

@harehare harehare commented May 8, 2026

Copy link
Copy Markdown
Owner

No description provided.

@codspeed-hq

codspeed-hq Bot commented May 8, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 45.93%

⚡ 7 improved benchmarks
✅ 22 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
eval_array_chained_operations 10.8 ms 9.3 ms +15.63%
eval_array_map 9.3 ms 8.2 ms +12.9%
eval_array_filter 11.7 ms 9.9 ms +18.33%
eval_fibonacci 57.5 ms 42.3 ms +35.99%
eval_while_speed_test 17.3 ms 12.3 ms +41.4%
eval_function_call_overhead 1,450.5 µs 993.9 µs +45.93%
eval_nested_function_calls 1,077.4 µs 828.8 µs +30%

Comparing perf/wrap-in-box (5cbf30d) with main (1273e69)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (5db3744) during the generation of this report, so 1273e69 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates mq-lang’s runtime representation to reduce move/clone costs by boxing (heap-allocating) heavier RuntimeValue payloads—specifically Markdown nodes and function parameter lists—and then adjusts downstream crates and tests to the new representation.

Changes:

  • Changed RuntimeValue::Markdown to store Box<mq_markdown::Node> and RuntimeValue::Function to store Box<AstParams>.
  • Added RuntimeValue::new_markdown(...) and updated call sites to correctly clone/move out of Box<Node> as needed.
  • Updated multiple consumers (CLI/grep, web API, WASM, LSP, crawler) and a large set of tests to match the new runtime layout.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/mq-web-api/src/api.rs Adjust Markdown extraction to clone from Box<Node>.
crates/mq-wasm/src/script.rs Move Node out of boxed Markdown runtime values when rendering.
crates/mq-run/src/grep.rs Adjust Markdown-to-nodes conversion for boxed nodes.
crates/mq-run/src/cli.rs Update Markdown collection/flattening utilities for boxed nodes.
crates/mq-lsp/src/execute_command.rs Move Node out of boxed runtime values for Markdown output.
crates/mq-lang/tests/integration_tests.rs Update integration tests to construct/compare boxed Markdown runtime values.
crates/mq-lang/src/lib.rs Update unit tests and Markdown rendering logic for boxed nodes.
crates/mq-lang/src/eval/runtime_value.rs Core change: box Markdown nodes + function params; add new_markdown; update helpers.
crates/mq-lang/src/eval/env.rs Update tests for boxed function params.
crates/mq-lang/src/eval/builtin/convert.rs Update Markdown construction and markdown-string conversion to account for boxed nodes.
crates/mq-lang/src/eval/builtin.rs Update multiple builtins for boxed nodes/params and node extraction/replacement.
crates/mq-lang/src/eval.rs Update evaluator to construct/use boxed Markdown values and boxed function params.
crates/mq-crawler/src/crawler.rs Move Node out of boxed runtime values when building Markdown output.

Comment thread crates/mq-lang/src/eval/builtin.rs Outdated
harehare and others added 4 commits May 8, 2026 14:27
…kdown constructor

- Box<Node> in RuntimeValue::Markdown reduces enum size from 176 → 40 bytes
- Add RuntimeValue::new_markdown(node) as the canonical constructor
- Replace all Markdown(Box::new(...), None) call sites with new_markdown()
- Restructure nested Node pattern matches in builtin functions to use &mut **node
- Update all crates (mq-run, mq-wasm, mq-lsp, mq-crawler, mq-web-api) accordingly
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@harehare harehare force-pushed the perf/wrap-in-box branch from a244f20 to bb1d50c Compare May 8, 2026 05:32
@harehare harehare requested a review from Copilot May 8, 2026 11:55
@harehare harehare merged commit 2ae90a2 into main May 8, 2026
9 checks passed
@harehare harehare deleted the perf/wrap-in-box branch May 8, 2026 11:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

}

Ok(RuntimeValue::Markdown(
Box::new(std::mem::take(node)),
Comment on lines 90 to 96
/// An array of runtime values.
Array(Vec<RuntimeValue>),
/// A markdown node with an optional selector for indexing.
Markdown(Node, Option<Selector>),
Markdown(Box<Node>, Option<Selector>),
/// A user-defined function with parameters, body (program), and captured environment.
Function(AstParams, Program, Shared<SharedCell<Env>>),
Function(Box<AstParams>, Program, Shared<SharedCell<Env>>),
/// A built-in native function identified by name.
})
.into()),
[RuntimeValue::Markdown(node, _), RuntimeValue::Boolean(ordered)]
if matches!(**node, mq_markdown::Node::List(_)) =>
Comment on lines +1916 to +1918
[RuntimeValue::Markdown(node, _)]
if matches!(**node, mq_markdown::Node::Definition(_) | mq_markdown::Node::Link(_)) =>
{
Comment on lines +1927 to +1929
[RuntimeValue::Markdown(node, _)] if matches!(**node, mq_markdown::Node::Image(_)) => {
if let mq_markdown::Node::Image(mq_markdown::Image { title, .. }) = &mut **node {
std::mem::take(title)
})
.into()),
[RuntimeValue::Markdown(node, _), RuntimeValue::Boolean(checked)]
if matches!(**node, mq_markdown::Node::List(_)) =>
Comment on lines +2036 to +2038
[RuntimeValue::Markdown(node, _), RuntimeValue::String(lang)]
if matches!(**node, mq_markdown::Node::Code(_)) =>
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants