Skip to content

Make imports from unrealised derivations work well with queries - #22

Closed
shlevy wants to merge 18 commits into
NixOS:masterfrom
shlevy:dynamic-import-queries
Closed

shlevy wants to merge 18 commits into
NixOS:masterfrom
shlevy:dynamic-import-queries

Conversation

@shlevy

@shlevy shlevy commented May 16, 2012

Copy link
Copy Markdown
Member

I'm opening this pull request now to have a place for a dialog as I work on this. I'll let you know when it's done and ready to pull.

shlevy added 16 commits May 15, 2012 23:00
…ilable due to read-only mode

I'm not sure if the exclamation point is valid in the xmlOutput case, this may
change in a later commit
…hose name cannot be evaluated in readonly mode should keep the VersionDiff unchanged
@shlevy

shlevy commented Jun 7, 2012

Copy link
Copy Markdown
Member Author

Ok @edolstra , I think this is ready for review. nix-env -q should now be more versatile in the import from unrealised derivation case. Future work includes adding a flag to allow nix-env -q to realise such derivations, and possibly some sort of max-depth feature for queries (though I think that issue will be better addressed when we have a real broken case in front of us).

@shlevy

shlevy commented Jun 22, 2012

Copy link
Copy Markdown
Member Author

@edolstra ping?

Comment thread src/nix-env/nix-env.cc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't it better to just omit unknown attributes rather than emit a value like "!name-unknown-..."? Especially in the XML output case, omitting an attribute shouldn't cause any problems. In the text output case, it might cause problems if the output is processed by a script like "awk { print $3 }". But in that case I would prefer a shorter string like "?".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Alright, I'll just omit the fields in every case unless you know of a specific case where the field needs to be output.

@shlevy

shlevy commented Aug 29, 2012

Copy link
Copy Markdown
Member Author

Whatever happens with #31, this definitely isn't the way we want to go.

@shlevy shlevy closed this Aug 29, 2012
@shlevy
shlevy deleted the dynamic-import-queries branch March 10, 2014 10:54
edolstra added a commit that referenced this pull request Apr 25, 2017
Print syntactially invalid attribute names as strings.
meditans referenced this pull request in Ericson2314/nix Aug 28, 2020
ConnorBaker pushed a commit to ConnorBaker/nix that referenced this pull request Jul 25, 2025
…0639c2-2b4c-4741-9fb8-959a7cf48281

Release v3.2.1
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request Jun 1, 2026
…oducer-record cost, soundness-clean

Implemented Layer 1 of the async-producer-recording plan: deferFlush flag threaded
recordSync -> SqliteTraceStorage::record -> Recorder::record (defaulted false, zero blast
radius; 181 record/CA tests pass). Env-gated NIX_PRODUCER_DEFER_FLUSH=1: producer path skips
the per-record flush() (recorder.cc step 7); entities buffer in pending* and drain at the
destructor flushExclusive(). In-memory caches still update via publishRecord, so
getCurrentTraceHash (the producerMap edge) is unaffected.

Soundness VALIDATED (not assumed):
- byte-identical eval output, defer-flush on vs off;
- cross-process warm-HIT preserved (proc1 cold-record defer-flush -> proc2 NIX_ALLOW_EVAL=0
  HITS) on a baseline-warm-hitting file eval; control confirmed the python3Packages --expr
  shape warm-misses even at baseline (workload artifact, not defer-flush);
- Sessions.trace_id has NO FK so deferred entity flush can't FK-violate the Sessions write;
- durability-timing change stated (crash loses buffered producers = future miss, never wrong).

Cost MEASURED (python3Packages, 3,201 producers): record.timeUs 2.699s -> 1.623s (-40%);
flushUs 1.126s -> 0.046s (-96%, the residual is the single teardown flush); hashUs unchanged
(0.78s — Layer 1 doesn't touch CPU). Matches the §3a split (flush was ~44%).

Honest state: real soundness-clean -40% on the §3b-dominant record cost, but not alone
net-positive (end-to-end needs the full aggressive recorder + this + the §21 verify win, likely
+ Layer 2 for the ~60% residual CPU). Shippable low-risk §3b improvement on its own (default-off).
Recorded follow-up NixOS#22.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request Jun 1, 2026
… (identical DB rows) + win is wall-confirmed (~9%)

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request Jun 1, 2026
…chmark: stat overstates, WALL (-9%) is honest

The user asked to validate the perf claim. Found a measurement-honesty issue: NixOS#22's headline
stats (flushUs -96%, record.timeUs -40%) EXCLUDE the teardown flush — maybePrintStats runs from
the CLI command BEFORE the store destructor, where defer-flush's batched drain of ~3,201
producers actually happens (lifecycle.cc:464). So the stat moved cost to an uncounted teardown.

The WALL number is the honest one and confirms the win is real (not hidden): OFF 12.11s -> ON
10.97s = -1.14s / -9%, tight across 3 runs, and -1.14s ~= the 1.086s flushUs drop — so batching
3,201 checkpoint+COMMITs into ONE teardown flush genuinely saves ~1.1s.

Corrected Layer 1 claim: ~9% / ~1.1s WALL on cold derivation-dense record (supersedes NixOS#22's
stat-led -40%/-96% framing; those internal timers exclude teardown, not the headline).

Scope caveats: COLD-record only (hot dedups via producerMap, barely hits the flush path; §3b's
14x hot is a different issue Layer 1 doesn't touch). Semantics CONFIRMED unchanged (byte-identical
+ identical row counts prove deferFlush changes WHEN not WHAT).

Lesson (recurring): an internal counter gave a flattering number excluding a real cost; only the
end-to-end wall was trustworthy. Win is real but ~9%, not the ~40% the stat suggested.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request Jun 1, 2026
…rash-consistency hazard in committed Layer 1

Read flush + publishStateChange end-to-end. Found a real semantic issue in the committed Layer 1
deferFlush + an incompleteness in my NixOS#22/NixOS#23 validation.

Ordering inversion: publishStateChange commits a durable per-producer Sessions/History row
(sqlite-trace-storage.cc:683, insertHistory=true) — I only deferred step-7 flush(), so that row
is written while its Traces row sits unflushed in pendingTraces until teardown. Baseline flushes
Traces FIRST; deferFlush inverts to History-before-Traces.

Crash-only stale-serve hazard: nextTraceId = MAX(Traces.id) at open (lifecycle.cc:611). Crash
between publishStateChange (History(N) durable) and teardown flush (Traces(N) lost) -> next
process reuses id N for a different trace -> stale History(N) aliases it -> __ca producer lookup
mis-resolves to the wrong trace. Baseline lacks this.

My NixOS#22/NixOS#23 validation could NOT have caught it: byte-identical + row-count + cross-process-hit all
ran on CLEAN exit (teardown flushes N, window never opens). The hazard is CRASH-ONLY. "Soundness
clean" was an overclaim on happy-path-only evidence.

Severity: LATENT today (§3b default-off; conservative shape's flattened-dep backstop catches a
mis-resolved edge; needs crash + id reuse). But the AGGRESSIVE shape removes that backstop by
design -> becomes a candidate stale serve. MUST fix before aggressive ships.

Fix reframes Layer 2a: deferring publishStateChange too (buffer Sessions/History, write in teardown
txn AFTER Traces) restores ordering and closes the hazard -> 2a is the CORRECTNESS COMPLETION of
Layer 1, not optional perf. Interim alternative: crash-safe-monotonic trace IDs.

Action: add a crash/abrupt-exit soundness test (the class NixOS#22/NixOS#23 lacked); do NOT enable the
aggressive shape on Layer 1 alone; committed Layer 1 stays (correct on clean exit, latent-only,
default-off) with this caveat. Recorded follow-up NixOS#24.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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