Skip to content

map: no in-place append — merge + to_owned makes an array accumulated over a loop O(n²) #374

Closed

Description

@codetiger

Summary

There is no way to append to an array in place. The idiom is a map mapping {"path": "data.log", "logic": {"merge": [{"var": "data.log"}, [ … ]]}}, and that is O(n) twice over per append: merge builds the whole new array in the arena, then the mapping result is deep-cloned with to_owned() (dataflow-rs 3.14.0 functions/map.rs:366) and the old array dropped. An array accumulated over a 1000-sweep loop is O(n²).

The same shape shows up inside a single evaluation: reduce with merge(accumulator, [x]) copies the accumulator every step, and merge is charged one op, so ops_budget does not see the quadratic cost.

Workarounds today

Batching (append to a small buffer, fold into the log every K sweeps) cuts the merge cost by K but not the O(n) arena copy the log costs every step (#371).

Proposal

A write mode on map mappings: {"path": "data.log", "append": <logic>} (or "mode": "append"), pushing the evaluated value (or extending with an array) onto the existing array in place, with no to_owned of the whole.

Activity

  1. codetiger commented on Oct 1, 2026

    @codetiger
    MemberAuthor

    Fixed on branch fix/issues-369-377 (not yet pushed; it lands after PR #368) via dataflow-rs 3.15 (GoPlasmatic/dataflow-rs#69): a mapping takes "mode": "append" or "extend" and pushes onto the array in place, copying only the entry. Upstream measured a 1000-sweep log loop at 77 ms with merge vs 16 ms with append. Orion documents it on the map reference, and the clippy analysis treats an appending mapping as reading its target so the overwrite rules don't misfire. The ops_budget half (merge charged one op) is fixed by datalogic-rs 5.7 (GoPlasmatic/datalogic-rs#77).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions