Skip to content

fix(sharding): improve shard selection heuristic - #85

Merged
aslushnikov merged 2 commits into
mainfrom
enhance-shard-selection
Aug 7, 2026
Merged

aslushnikov merged 2 commits into
mainfrom
enhance-shard-selection

Conversation

@aslushnikov

Copy link
Copy Markdown
Contributor

This produces a better shard selection and provides a regression test
to prove it.

This produces a better shard selection and provides a regression test
to prove it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 78e925ce07

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sharding.ts Outdated
for (let index = 0; index < shards.length; ++index) {
const shard = shards[index];
const shardMissingSetup = missingSetup(shard, family);
const minOtherMissingSetup = cheapestK.has(index) ? cheapestKTotal - shardMissingSetup : cheapestKMinusOneTotal;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recompute co-host setup as shards are selected

When K > 1, every candidate outside cheapestK is scored as if the same cheapest K - 1 shards will accompany it, but the final slice(0, K) can select several such candidates and none of those assumed co-hosts. This occurs when multiple low-load shards lack expensive dependencies while a more-loaded shard already has them; the average term then omits setup copies that the selected combination actually introduces, potentially inflating the total work and worsening the final balance. Score candidate combinations or select iteratively while recomputing the remaining co-host setup.

Useful? React with 👍 / 👎.

This came up as we were authoring the article about the algorithm.
Turns out, the current shard selection is suboptimal.

This patch improves selection logic and adds a regression test.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 038c741fbf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sharding.ts Resolved
@aslushnikov
aslushnikov merged commit a97ec6d into main Aug 7, 2026
7 checks passed
@aslushnikov
aslushnikov deleted the enhance-shard-selection branch August 7, 2026 01:58
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