Repository navigation
fix(engine): a full link chart skips what it can't draw, and a self-link is one end (#1947) - #2223
Conversation
…ink is one end (opengeos#1947) From opengeos#2146's review, after it was merged: - A feature related to itself was counted as two new ends. With the chart at 2,999 and the feature not in it yet, its link to itself was left out although it needs only one place. It's now counted once. - A full chart still went through every destination of every feature: one with no room left tried each and drew none. With 1,500 pairs filling the chart, a later relationship of 10,000 features sharing one key with 10,000 others made 100 million tries. A feature the chart has no room for is now skipped whole, and one already in it goes straight to the destinations the chart holds (or to itself), which are the only ones it can still link to. What's drawn and what the notice says are unchanged by the second; the first draws the one link it left out.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| // Where a key's destinations already in the chart sit among its destinations, found when | ||
| // the chart has no room for another one and kept while it stays that size: a full chart | ||
| // then looks at these only, not at every destination of every feature. | ||
| let mut in_chart: HashMap<String, (usize, Vec<usize>)> = HashMap::new(); |
There was a problem hiding this comment.
Grouped minor nits on the new full-chart path (no change needed for correctness; I traced the skip, jump and self-link branches and they hold):
- The
(usize::MAX, Vec::new())sentinel inin_chartcould be anOption<(usize, Vec<usize>)>or a small struct, so the cache's "not yet computed" state is explicit rather than relying on no chart ever reachingusize::MAXnodes. rows.partition_pointanddrows.binary_searchboth rely ondrowsbeing sorted ascending. That holds becauseby_keyis filled by iterating rows in order, but nothing says so. A one-line comment at theby_keypush would keep it true under later edits.drows[i](line ~1415) anddrows[j](line ~1425) index rather than useget(). Both are guarded by the loop and range, so this is style, not a crash path, and it can wait for the release quality pass.- Coverage gap: no committed test reaches
next_self, i.e. a new origin atMAX_NODES - 1whose earlier destinations don't fit and whose own row comes later indrows. TheLastcase covers the held-destination jump, and theSelfcase covers a self-link that fits directly.
There was a problem hiding this comment.
Thanks for tracing the branches. All four points are left for the release quality pass:
- The
usize::MAXsentinel: the chart is capped at 3,000 nodes, so it can't be confused with a real count. AnOptionor a struct would make that explicit, but nothing behaves differently. drowssorted: this holds becauseby_keyis filled in row order. A comment there would only document it.- Indexing rather than
get(): both indexes are bounded by the loop and the range, as you say. - A test reaching
next_self: I traced it the same way. With a new origin at 2,999 nodes, earlier new destinations need two places and are skipped. The jump lands on the feature's own row, which needs one, and the link is drawn. Once that origin is in the chart,next_selfisNoneand the held-row list is rebuilt for 3,000. An extra test for code that works can wait for the pass.
There was a problem hiding this comment.
Claude autofix (declined): Left for the release quality pass. The comment says no change is needed for correctness, and the points are style or extra coverage: the sentinel's form, a comment on the sorted drows invariant, indexing vs get(), and a test for next_self. The drows ordering does hold, since by_key is filled in row order.
Code reviewBugs
Security
Performance
Quality (grouped inline comment posted at
AGENTS.md
Prior reviews: no existing threads, so nothing was left alone. Note on testing: the PR says the engine tests were run only on Windows, and Linux was not run. CI should cover this. Change sizeCompared: the whole PR against main (merge base 803a014 to PR head 2ec51cb).
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. |
|
Claude autofix
|
| let drow = drows[i]; | ||
| // A feature related to itself is one end, not two. | ||
| let origin_new = a.is_none(); | ||
| let dest_new = !index.contains_key(&(dm, d.id, drow)) && !(origin_new && (om, o.id, orow) == (dm, d.id, drow)); |
There was a problem hiding this comment.
Possible bug in the PR description: the self-link "fix" doesn't change behaviour. On main the count was usize::from(a.is_none()) + usize::from(destination != origin && !index.contains_key(&destination)). For a self-related feature, destination == origin, so the destination term was already 0 and the feature counted as one end. The new dest_new is logically identical in every case: when origin == destination, a is None exactly when the origin is not in index, so the new expression is also false. I could not find a case where main counts a self-link as two.
That means the new Self case in a_link_chart_says_what_its_limits_leave_out should pass on main too, which conflicts with the "Reproduced first … left: (1500, 2999)" output in the PR description. Could you run that test against main and confirm it fails there? If it passes, the self-link part is not a fix. The description and test should then say so, or a different reproduction should be found. Confidence: about 80%, from reading the diff; I have not run it.
The full-chart skip/jump logic (the in_chart cache and next_self) does look equivalent to the old behaviour to me, with no change in what's drawn.
There was a problem hiding this comment.
Yes: against today's main it isn't a fix. #2201 started counting a feature related to itself as one end (the destination != origin you quote) after this PR was opened. The (1500, 2999) in the description came from this branch's first base, 803a014, which is before #2201. With main merged in, dest_new gives the same result as main's line and the Self block passes on main too. It stays only as a check of that case at 2,999 features.
#2201 also skips a feature the chart has no room for, which was the other half of this PR. The one part main doesn't have is this: once a destination has no room, a feature already in the chart goes straight to the next destination the chart holds (or to itself), not through each one in turn. I've corrected the description to say so. I'm also timing that case against main and will add the numbers there.
| } | ||
| u.run("share.linkChart", &json!({})).unwrap(); | ||
| // First draws 1 link (2 features), Fill 1,499 (2,997), and Self its feature's link to itself (1 more). | ||
| assert_eq!((drawn("Relationships").0, drawn("Relationships").1), (1501, 3000)); |
There was a problem hiding this comment.
AGENTS.md asks for both sides of a limit to be tested: lossy input gives the notice, clean input gives none. This new block checks the drawn counts only, not the notice. At 1,501 links and 3,000 features, left should be None, so please assert that share.linkChart's notice for this session is empty (the notice_mark / said pattern used earlier in this test works here). Confidence: high that the assertion is missing; the rule applies because this is a clean case.
Code reviewBugs
Security
Performance
Quality
AGENTS.md
I did not run the tests. My conclusions come from reading the diff and the surrounding code. Change sizeCompared: the whole PR against main (merge base 230cd1e to PR head 69e03c4).
|
Summary
Follow-up to #2146 (#1947). Its review came in after it was merged; this does what it found.
Since this was opened, #2201 on main has made two of the three changes below: the self-link count, and skipping a feature the chart has no room for. With main merged in (69e03c4), this PR still changes only the third: once a destination has no room, a feature already in the chart goes straight to the destinations it can still link to.
A feature related to itself was counted as two new ends (now on main too, from fix(engine): address release sweep correctness findings #2201). When a relationship joins a layer to itself on the same key, a feature can be its own destination. With the feature not yet in the chart,
share.linkChartcounted its link as needing room for two, the origin and the destination, though they are one feature. At 2,999 features that link was left out with one place free. It now counts once. The notice already counted the link, so nothing was hidden, but the chart was one link short.A full chart still went through every destination of every feature. A feature the chart had no room for tried each of its destinations and drew none, and the 20,000-link limit never stopped it, since no links were added. After 1,500 pairs fill the chart, a relationship of 10,000 features sharing one key with 10,000 others made 100 million tries. Now:
This doesn't change what's drawn or what the notice says; it only stops the tries that can't draw anything.
Testing
Engine
a_link_chart_says_what_its_limits_leave_outadds a Self case on its own session. First and Fill, as in the First, Fill and Last case, bring the chart to 2,999 features; then comes a relationship of a layer to itself on one key. The page draws that feature's link to itself: 1,501 links and 3,000 features.Reproduced first, with
sharing.rsas on main at 803a014, before fix(engine): address release sweep correctness findings #2201: the feature's link to itself was left out, with one place free.Since fix(engine): address release sweep correctness findings #2201 it passes on main too, so it stays only as a check of that case.
The full chart, timed with a test not committed (1,500 pairs, then 10,000 features each related to the same 10,000):
share.linkCharttook 5,980 ms with only the self-link fix and 16 ms with this PR (the workspace'stestprofile, optimised with debug info). That case is now fast on main as well, through fix(engine): address release sweep correctness findings #2201's skip of a feature with no room. The case only this PR speeds up is features already in the chart that relate to many with no room; I'm timing it against main and will add the numbers here.On Windows 11 x64, based on main 803a014:
cargo fmt --all --check, the engine's 23 tests matchinga_link_chart_says,shareorlink,cargo clippy -p rustgis-engine --all-targets -- -D warningsand, with CI's toolchain,cargo +1.100.0 clippy -p rustgis-engine --all-targets -- -D warnings -A clippy::needless_boolpass (the-Ais Windows-only, formain'scfg(unix)block insource/shp/cache.rs). CI passes on the merge of main (69e03c4).Not run: the whole of
cargo xtask ci(the engine's other tests andhostile_params_never_panicamong them), the browser build, and Linux or macOS.UI evidence
No visible change in the app. On main a full chart is already made without the wait in the timed case above. With this PR it is also made without the wait when features already in the chart relate to many that have no room.
Related issue
Follows #2146, for #1947.
Summary by CodeRabbit