Skip to content

Native save(): merge only the values that changed (rebased #246) - #569

Merged
tae898 merged 1 commit into
mainfrom
fix/245-save-changed-only
Dec 3, 2026
Merged

tae898 merged 1 commit into
mainfrom
fix/245-save-changed-only

Conversation

@tae898

@tae898 tae898 commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

On the native build, save() of a saved record now merges only the properties that changed, as the caller holds them (an ndarray stays an array), instead of every property. The stored row has already been compared with the copy of the values as read, so a value that is as read is already stored. A save that changes nothing still runs its UPDATE with every value, so update events fire as before. This is #246 (head 324e41d) rebased onto main, where save() has changed since, with one new test: the stored properties after save() are the same as after an UPDATE ... MERGE of every property.

Related issues

Closes #245

Performance changes

Timed A/B on the rebased head (2026-12-03, native build, laptop timed lane, 12 rounds, A/A control; arm A is the CI wheel 26.12.1.dev0 with records.py of main c9b8b55, arm B the same wheel with records.py of this PR at f3e28dd). Below 1 means B is faster:

record, one property changed role B/A median [95% CI] A/A (Z/A) median [95% CI] clean pairs A us per save B us per save
small (vertex P, id and n) no harm 1.0033 [0.9887, 1.0112] 1.0017 [0.9920, 1.0156] 12 86.3 86.1
medium (20 properties and a 768-float vector) gain 0.7685 [0.7665, 0.7706] 1.0033 [1.0015, 1.0077] 12 334.5 257.3
record kit control A median us B median us
small control_insert_us 27.09 27.31
small control_read_us 16.67 16.81
medium control_insert_us 27.44 27.48
medium control_read_us 16.68 16.76

Both A/A controls are clean and the controls are flat. The earlier A/B of #246 (2026-11-04) agrees: medium 0.797 [0.792, 0.802], small 1.002 [0.991, 1.007].

Docs

None: no page describes what save() sends.

Checklist

  • A regression test fails on the old code and passes on the new (tests/test_native_save_merge.py: 5 of 8 fail on main, all pass here; native overlay on the 26.12.1.dev0 wheel)
  • The test suite that the change can affect passes (see the checks)
  • uvx pre-commit run --files <changed files> passes

The stored row equals the copy of the values as read (save() checks that before it writes), so a value that is as read is already stored.
The UPDATE carried every property of the record; it now carries the changed ones, as the caller holds them (an ndarray stays an array).
A save that changes nothing still runs its UPDATE with every value, so update events fire as before.
Rebased from #246 onto main (save() now goes through _command_first_row), plus a test that the stored properties are the same as after a MERGE of every property.
@tae898

tae898 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

I timed PR #569 (the #246 patch rebased onto main) as the rule of my 2026-12-01 comment asks: no measured shape harmed and a clear gain on one is enough.

The A/B ran on the native build, on the laptop's timed lane (cores 6 and 7), as paired runs of 12 rounds in A, B, Z order, with A/A as the control. Arm A is the CI native wheel 26.12.1.dev0 with _native/records.py of main at c9b8b55. Arm B is the same wheel with only records.py of PR #569 at f3e28dd (nothing else differs), and arm Z is A again. Each run also checks, untimed, what the UPDATE carries: every value on A and Z, exactly the changed one on B. Ratios are the median of the per-round B/A ratios with a 95% bootstrap interval; below 1 means B is faster.

record, one property changed role B/A median [95% CI] A/A (Z/A) median [95% CI] clean pairs A us per save B us per save
small (vertex P, id and n) no harm 1.0033 [0.9887, 1.0112] 1.0017 [0.9920, 1.0156] 12 86.3 86.1
medium (20 properties and a 768-float vector) gain 0.7685 [0.7665, 0.7706] 1.0033 [1.0015, 1.0077] 12 334.5 257.3
record kit control A median us B median us
small control_insert_us 27.09 27.31
small control_read_us 16.67 16.81
medium control_insert_us 27.44 27.48
medium control_read_us 16.68 16.76

Both A/A controls are clean, both new-record and point-read controls are flat, and the rule is met: the small record is not slower (the interval lies inside [0.97, 1.03]) and the medium record saves in 0.7685 [0.7665, 0.7706] of the time. I am marking this PR ready now and will merge it when every check is green.

The tables are generated from the kit's rows.jsonl by a script, not typed.

@tae898
tae898 marked this pull request as ready for review December 3, 2026 11:47
@tae898
tae898 merged commit 3a18181 into main Dec 3, 2026
42 checks passed
@tae898
tae898 deleted the fix/245-save-changed-only branch December 3, 2026 11:55
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.

native: save() of a saved record merges every property, not the ones that changed

1 participant