Skip to content

[COLLECTIONS-722] Reuse the active path in nested iterator chains - #760

Closed
rishabhdaim wants to merge 1 commit into
apache:masterfrom
rishabhdaim:codex/COLLECTIONS-722-iterator-throughput
Closed

rishabhdaim wants to merge 1 commit into
apache:masterfrom
rishabhdaim:codex/COLLECTIONS-722-iterator-throughput

Conversation

@rishabhdaim

Copy link
Copy Markdown

Nested IteratorChains followed the full chain for every value. The iterator-of-iterators overload also ran out of stack on deeply nested inputs.

Keep the path to the active iterator and reuse it until the source changes or a shared child is accessed independently. Use the same traversal for lazy sources. Keep the original delegation links for remove(), including unmodifiable wrappers.

A 50,000-layer chain returning 50,000 values timed out after five seconds with stack safety alone and passes with this change. The other regressions cover on-demand source access, lookahead after a shared child advances, and removal through two parents sharing a child.

The full Maven build passed on Java 21 with 22,549 tests reported, 82 skipped, and no failures.

JMH 1.37 on Java 21, building and draining a chain of 256 values

Layers Stack-safe baseline This patch Oak
1 0.90 µs 1.08 µs 0.74 µs
8 34.6 µs 2.65 µs 1.15 µs
1,024 6.14 ms 16.8 µs 25.0 µs

At 1,024 layers, allocation fell from 12.3 MB to 80.6 kB per operation. The one-layer case stayed at 96 B per operation.

COLLECTIONS-722. This complements #758, which covers chained iterable views. The active-path approach follows OAK-12558.

OpenAI Codex assisted with the implementation, tests, and benchmarks.

Retain the active path across values and keep removal delegated through the original iterators. Use the same traversal for lazily supplied iterators.

Assisted-By: OpenAI Codex
@rishabhdaim

Copy link
Copy Markdown
Author

Superseded by #758, which now includes the iterator-chain changes.

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