Skip to content

fix(cost): print a summary build's operation counts to three decimals - #1417

Merged
milindsrivastava1997 merged 2 commits into
mainfrom
fix/cost-update-ops-rounding
Nov 18, 2026
Merged

milindsrivastava1997 merged 2 commits into
mainfrom
fix/cost-update-ops-rounding

Conversation

@milindsrivastava1997

@milindsrivastava1997 milindsrivastava1997 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A summary build's cost detail printed its operations per row unrounded, e.g. build Kmv into 1 states: 300000 rows x 304.9256135696759 ops (KMV's compared hashes per row are fractional). These counts now print through one helper, operations_text: three decimals, trailing zeros dropped. Whole counts print as before ("121"), fractional ones keep their value ("304.926"), and float noise doesn't show ("69.99993…" prints as "70"). Raised in the review of #1284.

Review guide

  • crates/cost/src/node/usage/mod.rs: operations_text, used by the SummaryAgg build detail, the SummaryTumblingWindowChain build detail and the state-allocation note.
  • crates/cost/src/node/usage/tests.rs: one test for the helper and one per site, over a shared fixture (user_id_sketch_detail).
  • Two commits: the first used :.0; the second (review) replaces it with the helper.

Behavior: before → after

KMV build over 300,000 rows at k = 4,323:

-build Kmv into 1 states: 300000 rows x 304.9256135696759 ops, 30 group visits; ...
+build Kmv into 1 states: 300000 rows x 304.926 ops, 30 group visits; ...

Interfaces

None. Only the human-readable detail string changes; charged costs are unchanged.

Algorithm changes

None.

Decisions and open questions

  • Three decimals with trailing zeros dropped, not :.0: :.0 printed a count under 0.5 as "0 ops" while still charging it. Not plain :.3 either, which would print every whole count as "121.000" and change every snapshot.
  • The hash aggregate's {operations_per_row:.0} stays: it charges whole operations per row (rounded up).
  • Out of scope: plan-cost drift and snapshot tolerance (Testing infrastructure: tracking #1354 D2). Any fixed rounding still flips at a boundary.

Verification

  • a_build_detail_prints_its_operations_per_row_to_three_decimals, a_chain_detail_prints_its_operations_per_row_to_three_decimals and a_state_allocation_prints_to_three_decimals each fail when their site prints the raw f64 (e.g. 304.9256135696759 ops) and pass with the fix. an_operation_count_prints_to_three_decimals pins the helper.
  • cargo test -p asap-cost: 120 passed. cargo clippy -p asap-cost --tests -- -D warnings: clean.
  • cargo test --release -p asap-devtools --test corpus_snapshots -- --include-ignored: 8 passed. No corpus or sketch-plan snapshot changes: none on main has a fractional operation count.

Follow-ups

None.

🤖 Generated with Claude Code

https://claude.ai/code/session_014qhwq4GZoWwtfFWWr9CKkr

A KMV build's compared hashes per row are fractional, so its cost detail
printed e.g. "300000 rows x 304.9256135696759 ops". Print the build's
and the chain's operations per row, and the state allocation's, with
`:.0`, as the hash aggregate's detail already does. Charged costs are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014qhwq4GZoWwtfFWWr9CKkr

@milindsrivastava1997 milindsrivastava1997 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No bug in charged costs; the comments below are about display fidelity and test coverage.

Design note: rounding is fixed in three format strings one at a time. A single helper (e.g. fn ops(x: f64) -> String) used by the hash-aggregate, SummaryAgg, chain and allocation details would stop the next detail that interpolates an f64 count (merge_ops, estimate_ops) from repeating this.

Comment thread crates/cost/src/node/usage/mod.rs Resolved
Comment thread crates/cost/src/node/usage/mod.rs Resolved
Comment thread crates/cost/src/node/usage/mod.rs Resolved
Comment thread crates/cost/src/node/usage/tests.rs Resolved
Comment thread crates/cost/src/node/usage/tests.rs Resolved
@milindsrivastava1997

Copy link
Copy Markdown
Collaborator Author

Does this tackle the D2 concern in #1354 (comment)?

No. That comment is about golden churn from floating-point drift in plan costs: a no-op refactor moved costs by up to 3e-11 relative, which flips the 11th–12th printed digit. It proposes a relative-tolerance comparison in the snapshot check, or printing fewer digits.

This PR only rounds the ops-per-row count in a summary build's detail string. Plan costs are still printed at full precision, and the snapshot check has no tolerance. The overlap is small: one fractional value in the snapshot text is now rounded. And :.0 still flips at a .5 boundary, which is the near-boundary problem the comment raises against option 2.

Review of #1417: `:.0` printed a count under 0.5 as "0 ops" while still
charging it, and the detail no longer multiplied out to the charge.
`operations_text` prints three decimals with trailing zeros dropped, so
whole counts read as before ("121"), fractional ones keep their value
("304.926") and float noise does not show ("70"). The build, chain and
allocation details use it, each pinned by its own test, over one shared
fixture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014qhwq4GZoWwtfFWWr9CKkr
@milindsrivastava1997

Copy link
Copy Markdown
Collaborator Author

Addressed in 72ee6fe. On the design note: one helper, operations_text (three decimals, trailing zeros dropped), now serves the SummaryAgg build, the chain build and the allocation note. Whole counts print as before, so no snapshot changes. I left the hash aggregate at {operations_per_row:.0}: it charges whole operations per row (rounded up), and switching it would change corpus snapshot text without fixing anything. No detail interpolates merge_ops or estimate_ops today. Each of the three sites has its own test, and each test fails if its site is reverted.

Out of scope: plan-cost drift and snapshot tolerance (#1354 D2). Three decimals still flip at a rounding boundary; a tolerant snapshot comparison would cover both.

@milindsrivastava1997 milindsrivastava1997 changed the title fix(cost): print a summary build's operations per row as a whole number fix(cost): print a summary build's operation counts to three decimals Nov 18, 2026
@milindsrivastava1997

Copy link
Copy Markdown
Collaborator Author

Re the D2 question above: agreed, this PR does not address #1354 D2 and is not meant to. It answers the #1284 review note about the unrounded {update_ops} in a build's detail text (69.99993333806893 ops in distinct-two-forms). Plan costs and the snapshot comparison are unchanged; D2 (a relative tolerance in the snapshot check, or fewer printed cost digits) stays open in #1354. Since 72ee6fe the count prints to three decimals instead of :.0. A boundary flip is still possible, but only in the third decimal, and a tolerant comparison would cover it too.

@milindsrivastava1997
milindsrivastava1997 merged commit 3f8fd29 into main Nov 18, 2026
4 checks passed
@milindsrivastava1997
milindsrivastava1997 deleted the fix/cost-update-ops-rounding branch November 18, 2026 19:24
milindsrivastava1997 added a commit that referenced this pull request Nov 18, 2026
The KMV build's operations per row print to three decimals
(116.19991733920547 -> 116.2). No plan changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014qhwq4GZoWwtfFWWr9CKkr
milindsrivastava1997 added a commit that referenced this pull request Nov 18, 2026
…1278) (#1284)

* test(devtools): sketch plan snapshots for 32 small single-purpose workloads (#1278)

Each workload exercises one planner behavior: rollup across label sets,
top-k reuse, chain widths and sharing, avg as Sum / Count, and which
sketches an accuracy target or a declared value sign admits. Its
`covers` line says what the workload exercises, not which plan is
selected, so a plan change needs no rewording. Existing snapshots are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014qhwq4GZoWwtfFWWr9CKkr

* test(devtools): regenerate distinct-two-forms after #1417

The KMV build's operations per row print to three decimals
(116.19991733920547 -> 116.2). No plan changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014qhwq4GZoWwtfFWWr9CKkr

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant