Skip to content

Investigate, implement and benchmark Vamana graph builder batch sizes reordering #419

Open

Description

@rfsaliev

Claude suggested the following to address Dmitry's comment. It also requires <numeric>.

        // Grow batches geometrically so early inserts can see each other in the sparse
        // graph; otherwise a batch collapses onto one hub whose pruning orphans nodes.
        // Holds batch sizes until the prefix sum below turns them into bounds.
        std::vector<size_t> batch_bounds;
        // Bound: ramp-up batches + full-size batches + leading 0.
        batch_bounds.reserve(std::bit_width(batchsize) + num_batches + 1);
        batch_bounds.push_back(0);
        for (size_t size = 1, inserted = 0; inserted < num_nodes;
             size = std::min(2 * size, batchsize)) {
            batch_bounds.push_back(std::min(num_nodes - inserted, size));
            inserted += batch_bounds.back();
        }
        // Only the final remainder batch can be smaller than its predecessor. Moving it
        // into the ramp keeps sizes non-decreasing.
        auto last = std::prev(batch_bounds.end());
        std::rotate(
            std::upper_bound(batch_bounds.begin(), last, *last), last, batch_bounds.end()
        );
        std::partial_sum(batch_bounds.begin(), batch_bounds.end(), batch_bounds.begin());

Originally posted by @mihaic in #405 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions