Skip to content

feat: cap encoded block degree - #30

Merged
LittleSound merged 5 commits into
mainfrom
feat/limit-block-degree
Oct 20, 2026
Merged

LittleSound merged 5 commits into
mainfrom
feat/limit-block-degree

Conversation

@LittleSound

Copy link
Copy Markdown
Member

Closes #23

Sender-only change: frames keep the existing [degree, ...indices, k, bytes, checksum] layout from shared.ts, and decoder.ts is untouched, so existing scanners decode the new frames as before.

Changes

  • New packages/luby-transform/src/degree.ts: ideal / robust soliton, truncation (tail mass folded into the cap), CDF built once per encoder + binary-search sampling, partial Fisher–Yates index sampling (no infinite loop for k=1, empty for k=0).
  • createEncoder(data, sliceSize, options) accepts { compress?, maxDegree?, random? }; a boolean third argument still means compress.
  • Default degree distribution: robust soliton (c=0.2, δ=0.5) truncated at DEFAULT_MAX_DEGREE = 32. The web app and GIF export use it automatically.
  • maxDegree is plumbed through packages/generate; the CLI gets --max-degree <count>.
  • __benchmarks__/degree-distribution.ts: seeded benchmark against this repo's LtDecoder.
  • lt.test.ts uses seeded RNG (fixes the ~5% statistical flake), adds a k=1000 uncompressed case; threshold 250% → 200%.

Benchmark (seeded, 30 runs, received blocks / k)

k before mean / worst after mean / worst
100 141.5% / 206% 139.0% / 163%
1000 143.9% / 220% (4.4 s/run) 127.5% / 144% (0.1 s/run)
3000 OOM / did not finish 121.7% / 129%
5000 — 120.9% / 134%

Mean header ≈ 50 B/frame, worst case bounded at 144 B. Plain truncated ideal soliton (cap 16/32) gets worse at large k with this decoder (k=3000 cap 16: 194%), hence robust soliton.

With 20% frame loss at k=1000: 170% / 267% → 159% / 168% (mean / worst sent blocks / k).

Verification

  • pnpm run lint, vue-tsc, pnpm run generate: pass
  • pnpm vitest run: all new/updated tests pass; the only failure is the pre-existing test/slicing.test.ts snapshot on main (fixed in the dependency-update branch).
  • Wire-format test parses new frames with an independent DataView parser of the shared.ts layout.

Not done / follow-ups

  • The decoder's subset-key bookkeeping is roughly quadratic in block degree (why the old uncapped distribution couldn't handle thousands of slices) — worth a separate issue.
  • Not tested end-to-end on real devices (old scanner ← new sender).

Sample degrees from a Robust Soliton distribution (c = 0.2, delta = 0.5)
truncated at maxDegree (default 32) instead of the uncapped Ideal Soliton.
The CDF is now built once per encoder and sampled by binary search.

createEncoder() accepts an options object { compress, maxDegree, random }
as its third argument; a boolean is still accepted as compress. The frame
format and the decoder are unchanged, so existing scanners can decode the
new frames.
Use a seeded RNG for the fountain so the data-rate assertion no longer
flakes, and tighten the threshold from 250% to the 180% target.
Also expose it as --max-degree in the CLI.
- robustSoliton falls back to ideal soliton when R is not positive
  (c = 0, delta >= k) instead of producing NaN
- omit the spike when k / R lies beyond k, per the textbook definition
- k = 0 (empty uncompressed input) yields empty index lists instead of [-1]
- lt.test: add an uncompressed k = 1000 case and relax the deterministic
  threshold to 200% to leave margin (target is still 180%)
@netlify

netlify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for qrss ready!

Name Link
🔨 Latest commit 4c0f2db
🔍 Latest deploy log https://app.netlify.com/projects/qrss/deploys/6ad755950edd3125c8f006c2
😎 Deploy Preview https://deploy-preview-30--qrss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@LittleSound
LittleSound merged commit 8e906a6 into main Oct 20, 2026
6 checks passed
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.

Ability to limit number of indices

1 participant