Repository navigation
Description
Before you start
- I searched the existing issues and did not find a duplicate.
- This is a bug report, not a usage question.
What happened?
On a large layer, each edit leaves a full copy of the layer's rows in the Undo history, so memory use rises with every edit. Enough edits reach the machine's limit, and running out of memory ends the process, so unsaved edits are lost.
With a generated table of 300,000 rows and 62 fields (script below), each edit.setValue added about 0.74 GB:
| Edits | Peak memory |
|---|---|
| 0 | 1.9 GB |
| 4 | 3.7 GB |
| 8 | 6.7 GB |
| 12 | 9.7 GB |
A county parcel layer (448,126 features, 121 fields) follows the same pattern at about 1.8 GB and 1.2 s per edit. Field edits do too: in the join-and-calculate workflow on #1998's size line, Add Field and Calculate Field together account for 4.5 GB of a 9.4 GB peak.
Cause
A layer's rows are one shared block (Features { rows: Arc<Vec<Feature>> } in crates/data/src/lib.rs), which keeps project snapshots cheap. Each editing command takes a snapshot in Session::guarded_inner (crates/engine/src/lib.rs). The session restores it if the command fails, and otherwise keeps it as the Undo step. The command's first write goes through Arc::make_mut, which finds the block shared with the snapshot and copies all of its rows. So each edit copies the layer once, however small the change, and each Undo step keeps its own version of the layer, up to UNDO_LIMIT (40) steps.
Most of the copy is attribute values rather than geometry. The parcels have 54 million attribute values and 5.2 million vertices, so sharing geometry between versions would not help much on its own.
Steps to reproduce
python3 - <<'EOF'
import csv, random
random.seed(1)
with open("rows.csv", "w", newline="") as f:
w = csv.writer(f)
w.writerow(["x", "y"] + [f"f{i}" for i in range(60)])
for _ in range(300_000):
w.writerow([round(random.uniform(-93.5, -93.1), 6), round(random.uniform(44.8, 45.2), 6)]
+ [random.randint(0, 10**6) if i % 2 else f"text {random.randint(0, 999)}" for i in range(60)])
EOF
edits() { for ((i=0; i<$1; i++)); do printf -- '--cmd\0edit.setValue={"layer":"rows","row":%d,"field":"f1","value":%d}\0' $i $i; done; }
for n in 0 4 8 12; do
edits $n | xargs -0 /usr/bin/time -f "$n edits: %M KB peak" \
rustgis-cli run --cmd 'layer.addData={"path":"rows.csv","name":"rows"}' >/dev/null
doneThe first edit fits within the peak that reading the CSV leaves behind, so the growth shows from the second edit on.
Expected behavior
- An edit's memory cost is in proportion to what it changes.
- Memory use doesn't keep rising with the number of edits.
- When an operation won't fit in memory, RustGIS refuses it with a message, or says what it gave up, such as older Undo steps.
Possible fixes
These are independent and can land in any order.
- Bound Undo by memory as well as by step count. When the steps that hold their own copies pass a budget, the session drops the oldest and says how many it dropped. This stops the growth, though each edit still makes one copy while it runs. It stays in the engine and changes no saved file or command parameter.
- Add a memory regression test to CI. A fixed CLI workflow on generated data (load, Add Field, Calculate Field, Join Field, export, several edits) would check peak memory as a multiple of the loaded size. The limits start at today's values and come down as fixes land, so a new full copy from any source fails the test. It would run on Linux and needs no new dependency.
- Count the memory the session already holds. Each limit today plans for its own share of memory (
memory::SHARE) without counting the layers, Undo steps and tool outputs already held. That is problem 3 in Analysis limits: fail gracefully on allocation, scale with the machine, and cancel long runs #1291, which the work there solved for rasters. With an estimate of what is held, an operation that copies a layer could check that the copy fits before making it. This would build on Analysis limits: fail gracefully on allocation, scale with the machine, and cancel long runs #1291 and feat(data): the size of a file read into memory follows the computer's memory #2411. - Store rows so that unchanged values are shared, in shared blocks or with attribute values by column. An edit would then copy only the block or column it changes, Add Field would add a single column, and Join Field could share its target's columns. This changes
Feature/Features, which is the lead's decision, and it relates to the Exploratory item on per-feature memory in Tracking: large data (layers over 2 million features, slow hillshade and GeoTIFF writing) #1111, so it needs its own proposal. The saved project format can stay as it is.
I can take 1 and 2. 3 overlaps the memory-limit work, so we should agree who takes it first.
@opengeos/rustgis-maintainers, for 3 and 4. Related: #1111 (large data), #1291 and #2411 (memory limits), #1998 (where this was found).
How are you running RustGIS?
Command line (rustgis-cli)
Version
Operating system, browser and graphics
Debian 13, 31 GB of memory
Sample data
The generated table above.
Activity
pick2510 commentedon Nov 19, 2026
@Mavrick-F I'll take 3. It continues the memory-limit work in #1291 and #2411 (merged), where the limits already follow the computer's memory through
memory::physical(), and #2441's check will show whether it helps. 1 is in with #2437, and 2 is #2441.I'll post the plan here before starting, covering three things:
4 stays with the lead's proposal.
pick2510 commentedon Nov 19, 2026
For the longer term, an option beside 4, for the lead to weigh: keep a layer's loaded rows unchanged and record edits beside them.
A base and its edits. A layer would be a read-only base (the rows as loaded) plus a small set of edits keyed by feature id: rows changed, added and deleted. Edits never write to the base. A project snapshot shares the base and copies only the edits, so an Undo step costs what it changed. On the 300,000 × 62 table above,
edit.setValuewould add one row's values (a few KB) instead of 0.74 GB.What else it gives:
guarded_innerand the restore after a failed command keep working, and no command needs an inverse.Cost: every reader of
Features(drawing, queries, analysis, export, the attribute table) would have to see the base and the edits merged, and do so quickly. That touches far more code than 4, so it would need its own proposal and a PR series measured with #2441'scargo xtask memory. To keep the merged view fast, the edits could be folded into a new base once they grow past a share of it, or when a project is saved.Limits: an edit that touches every row (Add Field, Calculate Field over the whole layer) produces edits as large as the base. Storing attributes by column (4) is what fixes those, so the two would complement each other.
This doesn't change 3. The estimate of what the session holds works the same way, and with a shared base its numbers get smaller.
pick2510 commentedon Nov 19, 2026
Plan for 3, before I start.
What the session holds.
Sessionkeeps an estimate of what it holds: every distinct row allocation in the open project and in Undo and Redo, counted once however many snapshots share it. It reuses #2437's per-allocation estimate and its cache, so the count stays cheap. It adds in-memory rasters and standalone tables, and tool outputs count as the layers they become. The estimate is updated after each command, where #2437 trims the history, and is published torustgis_data::memoryas a process-wide figure. Several sessions in one process, as in Python, add their counts together.Room for a copy. A new
memory::room()gives the physical memory, minus what is held, minus a reserve for drawing and the window (the quarter thatSHAREplans for today). In the browser, or when the memory can't be read,room()is unknown and nothing changes.What checks before copying:
edit.*that change features, including Add Field, Calculate Field and Delete Field). The check runs where streamed layers are refused today, before the command runs. The first write copies the layer's rows because the Undo snapshot shares them, so the copy costs the layer's estimated size. If that doesn't fit inroom():memory::scaledand the file and project size limits from feat(data): the size of a file read into memory follows the computer's memory #2411). They plan for the smaller of today's share and whatroom()leaves, so a second large job doesn't plan as if memory were empty. Each limit keeps its floor, so nothing is refused that is accepted today on a machine with free memory. Their errors already name the limit and its value, and they would add what is held when that is the reason.Not in this: tools that write a new layer get no check before they run, because their output size isn't known ahead. They are covered by 2 and by the fallible allocations of #1291 step 1. This is engine and data only: no saved file, command parameter or interface change, except the new refusal message, which is translatable.
Tests: fixed memory amounts are passed in, as
scaledtakes them today:I'll measure with #2441's
cargo xtask memoryonce it lands: the edit series in this issue should stop at the machine's limit with the message, instead of being killed.fix(engine): bound undo history by memory (opengeos#2437)
fix(engine): free history only when an edit copies, and count backgro…
fix(engine): count set-aside history as held, check rows before writi…
test(xtask): peak memory check for command line workflows (opengeos#2441
fix(engine): Set Geometry and Move, Rotate, Scale read rows before wr…
Mavrick-F commentedon Nov 19, 2026
More on fix 4, changing how layers are stored. Fixes 1 and 2 are merged (#2437, #2441), and 3 is in #2445.
On an 8 GB laptop, RustGIS can open and map a county's parcels (450,000 features), but adding one field or making two edits needs more memory than the laptop has free. A layer's attribute values sit in one block, and any change copies the whole block so Undo can keep the old one.
I tried five ways of storing a layer on those parcels, and one fits: each field's values in their own column, split into chunks that Undo can share. The join-and-calculate job from #1998 dropped from 7.1 GB to 2.1 GB, and to 0.6 GB once the columns are typed. A one-value edit goes from about 1.8 GB to almost nothing. Undo keeps working as it does now.
Speed holds up. Drawing, labels and tools that read a few fields per feature run as fast as today, and two to three times faster with typed columns. Reading every field of every row, as export and plugins do, gets slower: about half a second more across the whole county.
This works with pick2510's base-and-edits idea above rather than against it. With shared chunks, a one-value edit already copies only its chunk, about 100 KB, so for edits in memory a separate edit layer adds little. Where base-and-edits matters is a base that stays in the file instead of memory, which is what data bigger than a county needs. Chunks make that easier: edited chunks in memory over chunks read from the file, with Undo working the same way. So I'd do columns first and build that on top.
The cost is churn. About 900 places in the code read features directly. The plan moves them a crate at a time onto a small set of accessors before storage changes at all, and the storage switch would come back here for a decision first.
Two things I'd do unless someone sees a problem:
Moving the 900 places would touch the same lines as the coordinate-system work in #2032, so I'll hold that part until #2032 is finished. If it would help to start sooner on files #2032 doesn't touch, say so.
Measurements
On the county parcel layer (448,126 features, 121 fields) the rows take 1.47 GB. The cell array is 1.24 GB of that: 54.2 million attribute values at 24 bytes each (
size_of::<Value>()). Text is 106 MB and coordinates 84 MB. A smallerValueisn't possible: 24 bytes is already the size of an enum holding aString.The layouts were built in a throwaway crate on
rustgis-dataand run through the join-and-calculate workflow from #1998's size line, keeping a snapshot before every step as Undo does. Peak live heap:Arc<Vec<Feature>>Valuerustgis-clion the same workflow (9.4 GB). The desktop app adds about 0.44 GB.Read speed, all 448k parcels, median of 5 (identical checksums):
ValuecolumnsWhat it takes besides the storage
get_mutand records the old row indesign::Change, borrowing rows the command holds;design::apply_withtakes 12 ms on 448k changes today because nothing is copied there. Columns have no&Featureto borrow, so change records need a column form, or a port rebuilds the layer as rows (~1.5 GB). Same for Add/Delete Field, Join Field and Delete.Features::shares,allocation_keyor==(edited_streamed,fresh_source_ids, label-state cleanup, time-slider rebind). Replace with an outerArcthat every write replaces, plus a geometry identity so attribute edits don't rebuild projected geometry.Vec<Feature>first.TEXTholding42reads asInt(gpkg.rs),parse_sourcekeepsFloatin Integer fields,Dataset::ensure_fieldignores an existing field's type. A per-chunkValuefallback keeps today's behaviour; the sources get fixed separately.Stages
Each lands and reverts on its own.
Features(row view,value(row, field), column operations), no behaviour change; plus an xtask count of direct.features/.attrsuses that CI won't let rise (upstream adds ~1,000 such lines a week).to_rows()helper).Valuecolumns with layer and geometry identity. Gate: the workflow ≤ 4.5 GB in the app (what an 8 GB laptop leaves after the OS and a browser); drawing, labels, a per-feature tool, the attribute table and an expression over every row within 1.2× of today, measured back to back; export timed end to end and reported (whole-row reads are 1.5–1.8× slower in the bench).Valuefallback. Decide on arrow-rs here (inCargo.lockviaparquet, dev-only today; measure wasm size first).Unchanged throughout:
Featureas the public row type (rows can always be built), saved projects,schema/project.schema.jsonand fixtures, geometry storage (until a separate decision), the plugin interface.Later, the same chunks make version comparison cheap (shared chunks compare by pointer) and allow editing layers read in place (edited chunks over file chunks, same snapshot Undo).
pick2510 commentedon Nov 19, 2026
Plan for 3, part 2: the limits that follow the computer's memory subtract what is already held. It builds on #2445 (part 1), so I'll open it once that is merged.
What is held, for the whole process.
rustgis_data::memorygets a process-wide figure of the memory held:What a limit plans for. Today a limit plans for a quarter of the memory (
SHARE). It will plan for the smaller of that quarter and what is left of the three quarters after what is held, the same three quarters #2445 checks edits against. On a 16 GB computer holding 4 GB, a job still plans for 4 GB, the same as today. Holding 10 GB, it plans for 2 GB. Every limit keeps its floor and ceiling, so nothing the fixed limits accept today is refused.Which limits:
memory::scaled: raster samples, output pixels, paged features, protocol buffer pages, density cells, buffer storage and the CSV read budget;Left as they are:
What is said:
gp.envreturnsheldBytes, and its limits are the ones in force at the time.Tests:
scaledtakes them today. Nothing held gives today's limits. Holding up to half the memory changes nothing. Holding more lowers the limits down to their floors, never below.RUSTGIS_MEMORY_BYTES: a file read that passes with the project empty is refused once the session holds most of the memory, with the message.Engine and data only: no saved file, command parameter or interface change, apart from the message and
gp.env's new key.fix(engine): check that an edit's copy fits beside what the session h…
fix(engine): say which history an edit's memory check dropped, and li…
fix(engine): set-aside history doesn't make up for less free than the…
docs(agents): sizing rule covers new work and says what memory::plann…
fix(data): memory limits and the edit check plan for what is held and…
docs(agents): size designs for real data, not the sample project (ope…
refactor(data): accessors for a layer's rows and fields, and a count …
fix(data): memory limits count the process's own control group (openg…
perf(data): Add Field copies a shared layer once, at its new length (o…