Skip to content

rust: use Rc<RuntimeValue> to avoid deep copies#212

Open
dshemetov wants to merge 3 commits intomainfrom
ds/rust-rc
Open

rust: use Rc<RuntimeValue> to avoid deep copies#212
dshemetov wants to merge 3 commits intomainfrom
ds/rust-rc

Conversation

@dshemetov
Copy link
Collaborator

@dshemetov dshemetov commented Oct 19, 2025

After a month of tinkering with overly clever lazy evaluation approaches and get tangled in too many lifetimes, I arrived at an unoriginal "Rc all the things!" solution, but hey, at least it's clean and does the job.

@netlify
Copy link

netlify bot commented Oct 19, 2025

Deploy Preview for mistql canceled.

Name Link
🔨 Latest commit 6b27dc8
🔍 Latest deploy log https://app.netlify.com/projects/mistql/deploys/68f55ab203941400080bd957

@dshemetov dshemetov changed the title rust: use Rc<RuntimeValue> to make a single json copy rust: use Rc<RuntimeValue> to avoid deep copies Oct 19, 2025
Copy link
Owner

@evinism evinism left a comment

Choose a reason for hiding this comment

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

Looks pretty good, thanks for doing this! Only thing I really care about is the Rc<> on the external interface, everything else looks gtg.

{
let runtime_data = data.try_into().map_err(|e| MistQLError::Runtime(e.to_string()))?;
query_runtime(query_str, &runtime_data)
pub fn query(query_str: &str, data: &Value) -> Result<Rc<RuntimeValue>, MistQLError> {
Copy link
Owner

Choose a reason for hiding this comment

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

Returning an RC runtime value feels like an implementation leak. We should return a bare value, and just use RC as an internal optimization rather than expose it to the interface.


// AST expression types for MistQL
#[derive(Debug, Clone, PartialEq)]
pub enum LiteralValue {
Copy link
Owner

Choose a reason for hiding this comment

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

NB: Could call this LiteralPrimitive, since technically [foo, bar] is considered an array literal.

Regex(MistQLRegex),
}

impl RuntimeValue {
Copy link
Owner

Choose a reason for hiding this comment

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

NB: Could also likely replace these constructor functions with pub fn rc(self) -> Rc<Self> such that we can do RuntimeValue::Boolean(true).rc(). Might be slightly clearer / more rust-y / not pollute the returned RuntimeValue struct with as many constructors.

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