[PR #57] tools: --shard balances by file size, so the parallel stage waits for nobody (output byte-identical) #109

Open
opened 2026-11-26 20:16:49 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/57
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9779


📝 Commits (2)

  • 30ade56 tools: --shard balances by size instead of taking every n-th shader
  • ff80152 rdna2spirv: a shard stops when it cannot size a file, instead of guessing 0

📊 Changes

2 files changed (+115 additions, -3 deletions)

View changed files

➕ tests/test_rdna2spirv_shard.py (+83 -0)
📝 tools/rdna2spirv.py (+32 -3)

📄 Description

Carried over from old PR 9779 by pes7 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9779, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
pes7: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

The parallel translation stage waits for its slowest shard, and the split ignores size. This balances the shards on input size; on a real 247-listing run the shards come out level and every output stays byte-identical.

--shard i/n took files[index::count] — round-robin over the name-sorted list, which balances nothing when shaders differ in size. shard_bucket() sorts by file size, largest first, and gives each file to the lightest bucket so far; a shard translates its own bucket. Every shard derives the same partition from the same directory listing, so the processes still do not talk to each other, make_game.py and the --shard i/n interface are unchanged, and each bucket is still handed out in name order.

Measured

Independent run by @nicolasabosch on 247 listings, four --shard i/4 runs plus --merge against one unsharded run:

  • 258 .spv files on both sides, all 258 byte-identical; merge has 247 entries;
  • heaviest of 4 shards by listing bytes: 266,003 with this change against an ideal of 265,966 (round-robin on the same list: 286,904).

And on the real 26,503-listing corpus by @exotiquee: round-robin is already within 2.6% of even at 8 shards and 6.8% at 16, so the honest expected gain there is 0-7%, growing with the shard count; the change levels the tail rather than rescaling the stage. That correction is in this description on purpose — the synthetic corpus I first measured on was skewed far more than the real one, and its 17-26% is not the claim.

A size that cannot be read stops the shard

Reported by @Zhenyettta: with a weight of 0 for one unreadable file, two shards can take the same shader while a third falls out of every bucket. Each shard derives the partition alone, so the one thing that must not happen is a shard placing a file by a number the others do not have. shard_bucket() now raises with the path and the advice to run the shard again.

Tests

tests/test_rdna2spirv_shard.py (5): the buckets are disjoint and complete for 1/2/3/4/8/16 shards, the same partition in every process, name order inside a bucket, a skewed listing beats files[::n] at 2/4/8 shards, one shard takes everything, and an unreadable size is refused. --merge and test_rdna2spirv_merge.py are unchanged. Independent runs also confirm resume: make_game.translate's plan includes translator_digest(), so parts from the old bucketing are never merged with new ones.

cc @ItsNotRexed @KoertLichtendonk

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md. (Not applicable: same shaders, translated by a different process.)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/57 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9779` --- ### 📝 Commits (2) - [`30ade56`](https://github.com/ubiquitarianism/leonida/commit/30ade563d809e16a5aa2636ac7b10610d6ed92e6) tools: --shard balances by size instead of taking every n-th shader - [`ff80152`](https://github.com/ubiquitarianism/leonida/commit/ff80152d2374b9680a082dd7350d5c79fa796969) rdna2spirv: a shard stops when it cannot size a file, instead of guessing 0 ### 📊 Changes **2 files changed** (+115 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_rdna2spirv_shard.py` (+83 -0) 📝 `tools/rdna2spirv.py` (+32 -3) </details> ### 📄 Description > Carried over from **old PR 9779** by `pes7` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9779`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `pes7`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): **The parallel translation stage waits for its slowest shard, and the split ignores size.** This balances the shards on input size; on a real 247-listing run the shards come out level and every output stays byte-identical. `--shard i/n` took `files[index::count]` — round-robin over the name-sorted list, which balances nothing when shaders differ in size. `shard_bucket()` sorts by file size, largest first, and gives each file to the lightest bucket so far; a shard translates its own bucket. Every shard derives the same partition from the same directory listing, so the processes still do not talk to each other, `make_game.py` and the `--shard i/n` interface are unchanged, and each bucket is still handed out in name order. ### Measured Independent run by `@nicolasabosch` on 247 listings, four `--shard i/4` runs plus `--merge` against one unsharded run: - **258 `.spv` files on both sides, all 258 byte-identical**; merge has 247 entries; - heaviest of 4 shards by listing bytes: **266,003** with this change against an ideal of 265,966 (round-robin on the same list: 286,904). And on the real 26,503-listing corpus by `@exotiquee`: round-robin is already within 2.6% of even at 8 shards and 6.8% at 16, so the honest expected gain there is **0-7%**, growing with the shard count; the change levels the tail rather than rescaling the stage. That correction is in this description on purpose — the synthetic corpus I first measured on was skewed far more than the real one, and its 17-26% is not the claim. ### A size that cannot be read stops the shard Reported by `@Zhenyettta`: with a weight of 0 for one unreadable file, two shards can take the same shader while a third falls out of every bucket. Each shard derives the partition alone, so the one thing that must not happen is a shard placing a file by a number the others do not have. `shard_bucket()` now raises with the path and the advice to run the shard again. ### Tests `tests/test_rdna2spirv_shard.py` (5): the buckets are disjoint and complete for 1/2/3/4/8/16 shards, the same partition in every process, name order inside a bucket, a skewed listing beats `files[::n]` at 2/4/8 shards, one shard takes everything, and an unreadable size is refused. `--merge` and `test_rdna2spirv_merge.py` are unchanged. Independent runs also confirm resume: `make_game.translate`'s plan includes `translator_digest()`, so parts from the old bucketing are never merged with new ones. cc `@ItsNotRexed` `@KoertLichtendonk` ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`. (Not applicable: same shaders, translated by a different process.) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#109
No description provided.