Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nitrite/nitrite-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.0.0
Choose a base ref
...
head repository: nitrite/nitrite-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.1.0
Choose a head ref
  • 2 commits
  • 23 files changed
  • 2 contributors

Commits on Aug 13, 2026

  1. Take a sorted page's order from the index instead of every document

    `find(ALL, orderBy("createdAt", Descending).limit(20))` asked for 20 rows and
    cost what draining the whole collection costs. `SortedDocumentStream` collects
    the entire result set before `BoundedStream` gets to drop 99% of it, and the cost
    is the decode, not the comparison, so it scales with document *size* as much as
    count. An index on the sort field bought nothing — the index was only ever used
    to filter — and page 50 cost exactly what page 1 cost, because the work finished
    before the skip applied.
    
    An index on the sort field already stores that field's value for every document.
    When the query has no filter, one sort field, a limit, and a simple unique or
    non-unique index on exactly that field, the keys now come from the index
    (`NitriteIndex.readSortKeys`) and `IndexedStream` fetches only the rows the page
    returns. On MVStore over 2000 rows each carrying a 150-element list, a `limit(20)`
    page went from ~125 ms to ~1 ms.
    
    The index replaces the documents only when it is a faithful stand-in for them: a
    multi-valued field is indexed once per element, so a duplicate-id check and an
    entry-count check catch it and fall back to the blocking sort. Ordering is decided
    by the same comparator either way — extracted as `DocumentSorter.compareValues` so
    the two cannot drift — over keys read from the index rather than from documents,
    which keeps nulls first and resolves ties in document-id order exactly as before.
    
    Where documents are small the index walk replaces a decode that was nearly free,
    so a sorted page over lean rows can cost a few hundred microseconds more than it
    did. The trade is deliberate: that loss is bounded and sub-millisecond, the win
    grows without bound with document size.
    
    New API is additive. `NitriteIndex.readSortKeys(long)` and
    `NitriteIndexer.readSortKeys(IndexDescriptor, NitriteConfig, long)` are `default`
    methods returning `null`, so an existing indexer plugin is unaffected and simply
    never takes the new path.
    
    `CollectionSortedFindTest` pins every sorted query against the same query on an
    unindexed collection — ascending, descending, deep pages, ties, strings, missing
    fields, unique indexes, and the multi-valued fallback — so a divergence in
    ordering fails outright. `CollectionSortedFindCostTest` runs on MVStore, where
    documents are actually serialized, and compares a sorted page over lean documents
    against one over fat documents at the same row count: only the decode differs
    between them, so it is stable under load in a way a wall-clock threshold is not
    (it reports 94x without this change and ~1x with it).
    
    Co-Authored-By: Claude Opus 5 <[email protected]>
    anidotnet and claude committed Aug 13, 2026
    Configuration menu
    Copy the full SHA
    ab91339 View commit details
    Browse the repository at this point in the history

Commits on Aug 22, 2026

  1. Make the sorted-page cost guard survive a slow runner

    The v5.1.0 tag build failed on the Windows runner and nowhere else, on this
    guard: fat 14.5 ms against lean 2.7 ms, a 5.4x ratio through a 4x threshold,
    with the index-ordered sort in place and working. `release.yml` gates on Build
    succeeding, so the Maven Central publish was skipped and 5.1.0 never shipped.
    
    The threshold was not the problem, the shape was. The guard compares a sorted
    page over lean documents against one over fat documents at the same row count,
    so that the index walk - identical in both - cancels and only the decode
    differs. But a page of 20 fat documents costs more to return than a page of 20
    lean ones no matter how the order was decided, and that difference is the floor
    of the ratio. On this machine it is noise; on the Windows runner it was most of
    the measurement.
    
    Asking for one row instead of twenty shrinks that floor twentyfold while leaving
    the discarded-row decode at full size. Measured here: 0.56x with the
    index-ordered sort against 85x without it, so a 3x threshold now sits five times
    clear of a passing run rather than seven-tenths of the way to a failing one.
    
    Test-only. Also dates the 5.1.0 changelog entry correctly.
    
    Co-Authored-By: Claude Opus 5 <[email protected]>
    anidotnet and claude committed Aug 22, 2026
    Configuration menu
    Copy the full SHA
    9f3f256 View commit details
    Browse the repository at this point in the history
Loading