feat(FN-5036): complete Step 1 — unify split-entry best-fit placement
Fusion-Task-Id: FN-5036 Fusion-Task-Lineage: 8df4174c-27f1-4d95-aded-bb2769384bc1
This commit is contained in:
committed by
gsxdsm
parent
36ef032a07
commit
1b53400a91
@@ -127,10 +127,12 @@ export function computeSplitPlan(packages, total, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Best-fit-decreasing assignment (FN-5002): iterate entries in descending
|
* Best-fit-decreasing assignment (FN-5002/FN-5036): iterate entries in
|
||||||
* weight order and place each entry into the shard that is closest to the
|
* descending weight order and place each entry into the shard that is closest
|
||||||
* per-shard budget without exceeding it; if all candidates would exceed budget,
|
* to the per-shard budget without exceeding it; if all candidates would exceed
|
||||||
* choose the minimum overshoot shard. Split-slice isolation rules are preserved.
|
* budget, choose the minimum overshoot shard. This best-fit-under-budget rule
|
||||||
|
* now applies uniformly to split and non-split entries while preserving
|
||||||
|
* split-slice isolation rules.
|
||||||
*
|
*
|
||||||
* @param {Array<{name:string, testFileCount:number}>} packages
|
* @param {Array<{name:string, testFileCount:number}>} packages
|
||||||
* @param {number} total
|
* @param {number} total
|
||||||
@@ -168,14 +170,7 @@ export function planShardAssignments(packages, total, options = {}) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let targetIndex = candidates[0] ?? 0;
|
const selectBestFitCandidate = () => {
|
||||||
if (entry.shardCount) {
|
|
||||||
for (const index of candidates) {
|
|
||||||
if (shardWeights[index] < shardWeights[targetIndex]) {
|
|
||||||
targetIndex = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let bestUnderBudgetIndex = null;
|
let bestUnderBudgetIndex = null;
|
||||||
let bestUnderBudgetProjected = Number.NEGATIVE_INFINITY;
|
let bestUnderBudgetProjected = Number.NEGATIVE_INFINITY;
|
||||||
let bestOvershootIndex = null;
|
let bestOvershootIndex = null;
|
||||||
@@ -203,12 +198,10 @@ export function planShardAssignments(packages, total, options = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bestUnderBudgetIndex !== null) {
|
return bestUnderBudgetIndex ?? bestOvershootIndex ?? candidates[0] ?? 0;
|
||||||
targetIndex = bestUnderBudgetIndex;
|
};
|
||||||
} else if (bestOvershootIndex !== null) {
|
|
||||||
targetIndex = bestOvershootIndex;
|
const targetIndex = selectBestFitCandidate();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shardAssignments[targetIndex].push(entry.shardCount ? {
|
shardAssignments[targetIndex].push(entry.shardCount ? {
|
||||||
name: entry.name,
|
name: entry.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user