Skip to content

Conversation

@benguild
Copy link
Contributor

@benguild benguild commented Dec 25, 2025

Title explains, I'll include comment(s) in the diff. I think this is correct (?) and tried to expand the tests as well, but please let me know if you see any issues.


// cellUnionDifferenceInternal adds (xid - y) to the CellUnion. It subdivides
// xid when there is partial overlap, narrowing y before recursing.
func (cu *CellUnion) cellUnionDifferenceInternal(xid CellID, y CellUnion) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this prior to the exported method to match C++ and have better proximity.

var cu CellUnion
for _, xid := range x {
cu.cellUnionDifferenceInternal(xid, &y)
cu.cellUnionDifferenceInternal(xid, y)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed OK to pass by value

return
}

y = y[lo:hi]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By reducing the size of "y" we're narrowing the search in the call to "ContainsCellID" and in recursive calls.

@jmr
Copy link
Collaborator

jmr commented Dec 29, 2025

Are there benchmarks for this?

@jmr jmr changed the title Optimizing CellUnionFromDifference to resolve TODO CellUnionFromDifference: Optimize Dec 30, 2025
@panmari
Copy link
Collaborator

panmari commented Jan 7, 2026

+1 to the comment above. Could you please implement a benchmark similar to BenchmarkCellUnionFromRange, then test the difference under your change?

@benguild
Copy link
Contributor Author

benguild commented Jan 8, 2026

Thanks all, I've seen the comments and when I'm able to clear the backlog on my side I'll take a look.

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.

3 participants