This commit is contained in:
33333-33333 2026-09-29 23:45:12 +09:00
commit f5fc9b76ce
73 changed files with 32628 additions and 376 deletions

View file

@ -0,0 +1,153 @@
# 5改善案の本体統合と再評価
## 対象
前回評価表の「Numeric tile cache」より上にあった次の5案を `index.html` に統合した。
1. 一般周期検出
2. perturbation series approximation
3. sparse active state
4. dynamic multi-reference
5. CPU Worker fallback
`Numeric tile cache` 以下は今回の対象外。基準は統合前の `index.html`(SHA-256 `8355da57...086a935`)。
## 実装
### 1. 周期検出
- direct f32 kernel に Brent 型 O(1) candidate search を追加。
- 単純な「近いから内部」判定は再評価で危険と判明したため、候補後に **2周期分の再一致**と **周期乗数 `|μ| < 0.95`** を確認してから `FIELD_INTERIOR_HEURISTIC=2` にする。
- `FIELD_INTERIOR_PROVEN=3` とは分離し、heuristic が1画素でもあれば `membershipCertified=false`。
- strict/export では無効。
- FAST perturbation 上の周期早期停止は撤回。forced-direct 診断で deep seahorse に false candidate が残ったため、deep path は series / continuation に任せる。
### 2. Series approximation
- reference worker で 1〜6次係数を更新。
- GPU に送るのは 1〜4次係数。5・6次は truncation error の安全側判定に使用。
- validity 条件を満たす最大 jump を reference ごとに計算し、FAST perturbation の初期反復を4次多項式評価へ置換。
- strict/export では series jump を無効化し、従来 recurrence を使う。
### 3. Sparse active state
旧 continuation は state/queues/mark をほぼ全画素サイズで持っていた。新構成は以下。
- `DeepState`: active slot ごと 32 B
- queue A/B: active slot ID
- `pixelMap`: active slot → pixel index
- membership: 1 bit/pixel bitset
- 初期 capacity: `active * 1.25 + 256`(全画素上限)
- correction により新しい `OPERATION_LIMIT` が生じた場合は、slot allocator を複雑化せず metadata から compact session を再構築する。
### 4. Dynamic multi-reference
- failure-guided reference recovery を最大3 passまで反復。
- 既に試した reference identity は再試行しない。
- 1 pass の改善が `max(8 pixels, 2%)` 未満なら打ち切る。
- 固定 2x2 / 3x3 配置ではなく、既存 failure sample + scorer を使って必要箇所だけ reference を追加する。
### 5. CPU Worker fallback
- WebGPU 非対応/初期化失敗時に最大4 Workerで direct Mandelbrot を描画。
- cardioid / period-2 bulb、有限 iteration、既存 palette の主要表示をサポート。
- JS `Number` で adjacent pixel を区別できない deep zoom では停止し、誤った deep image を出さない。
- CPU fallback の `OPERATION_LIMIT` と周期 heuristic は未確定扱い。WebGPU の high-precision path の代替ではなく互換経路。
## 再評価結果
### 周期検出
96×64、maxIter=8192、candidate は 65,536 iteration まで escape を追跡。
| view | production backend | 反復仕事量削減 | false candidate |
|---|---|---:|---:|
| overview | direct | 84.9% | 0 |
| period3-bulb | direct | 99.09% | 0 |
| period3-core | direct | 99.12% | 0 |
| seahorse-boundary | direct | 0% | 0 |
| exterior | direct | 80.0% | 0 |
| seahorse-deep | fast-extended | **周期停止を使用しない** | — |
forced-direct では seahorse-deep に false candidate が残るため、FAST 側を無効化した判断は維持する。
### Series approximation
production fast-reference worker の実出力を使用し、4次 series と直接 perturbation の delta を8点で比較。
| span | jump | 最大絶対誤差 |
|---:|---:|---:|
| 1e-5 | 53 | 7.11e-9 |
| 1e-7 | 446 | 7.74e-9 |
| 1e-9 | 930 | 7.46e-9 |
| 1e-11 | 1037 | 2.28e-9 |
reference build の一部として係数を作るため CPU 側の追加仕事はあるが、deep zoom ほど jump が大きい。実 GPU frame time はこの環境では測れていない。
### Sparse active state
standard 1,048,576 px の continuation workspace モデル。
| active ratio | 旧 | 新 | 削減 |
|---:|---:|---:|---:|
| 100% | 44.0 MiB | 44.13 MiB | -0.28% |
| 25% | 44.0 MiB | 13.89 MiB | 68.4% |
| 10% | 44.0 MiB | 5.64 MiB | 87.2% |
| 1% | 44.0 MiB | 0.686 MiB | 98.4% |
active がほぼ全画面なら pixel map + bitset の分だけわずかに悪化する。狙いは sparse frontier であり、その条件では効果が大きい。
### Dynamic multi-reference
production は failure-guided 最大3追加 reference。GPU end-to-end の `A_num` は実 GPU 不在で測れないため、前回と同じ f32 perturbation locality surrogate を再実行した。
seahorse span=1e-7:
- center 1 ref: class mismatch 2.578%
- center + 2x2 (5 refs): **1.445%**
- center + 3x3 (9 refs): 1.953%
reference を無制限に増やすのは逆効果になり得るため、「失敗箇所から選ぶ + 3 pass cap」は妥当。
### CPU fallback
production `cpuFallbackWorkerSource()` 自体を Node worker shim で実行。640×360、350 iter、7 run median。
- 1 Worker: 約 97.2 ms
- 4 Workers: 約 36.0 ms
- speedup: **2.70×**
- escaped / OP_LIMIT / heuristic / work count は 1 Worker と4 Workerで一致。
これはブラウザ 2D canvas compositing を含まない worker compute 値。
## 回帰・サイズ
- JS syntax: PASS
- production regression: **5/5 PASS**
- regression median: 約 0.08 s
- WGSL kernels: 19本、hash 更新済み
- `index.html`: 208,576 → 223,672 bytes(+7.24%)
- gzip -9: 52,563 → 57,198 bytes(+8.82%)
## 実 GPU 検証の限界
コンテナの Headless Chromium + SwiftShader は EGL 初期化に失敗し、WebGPU smoke を開始できなかった。そのため以下は未測定。
- stable frame p50/p95
- GPU series jump の実時間短縮
- sparse scatter/gather の実 GPU overhead
- dynamic multi-reference 導入後の production `A_num`
したがって **CPU/数値 surrogate を GPU frame-time として扱わない**。
## 結論
| 改善 | 統合判断 | 再評価 |
|---|---|---|
| 周期検出 | 採用(directのみ) | 高周期内部で非常に有効。FASTでは安全性不足のため無効 |
| Series | 採用(interactive) | deepほど jump が増え、有望 |
| Sparse active state | 採用 | active≪100%ならメモリ効果が明確 |
| Dynamic multi-reference | 採用(最大3 pass) | reference増加は非単調。failure-guided capが妥当 |
| CPU fallback | 採用 | 互換性改善。4 Workerで約2.7×、deep precision代替ではない |
次に実機で確認すべき優先順位は **series GPU frame time → sparse continuation latency → multi-reference の `A_num`**。

View file

@ -0,0 +1,6 @@
# Integrated improvements
- `IMPLEMENTATION.md`: 実装内容、設計判断、再評価、限界
- `results.json`: 再現用の生データ
- benchmark: `../../experiments/integrated_bench.mjs`
- regression: `../../tests/regression.mjs`

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,426 @@
{
"date": "2026-09-29",
"scope": [
"direct periodicity heuristic",
"perturbation series approximation",
"sparse active continuation state",
"dynamic failure-guided multi-reference",
"CPU Worker fallback"
],
"baseline": {
"path": "../mandelbrot_work/index.html",
"sha256": "8355da57e2f546c4e1cbeb2237e9dbfb65168b6d4c254929a2b02078c086a935",
"bytes": 208576,
"gzip9Bytes": 52702
},
"integrated": {
"sha256": "544820c5024cf6d56e012db6d1bec3ddfcef5d833691b890baa64b26c5c2ee5a",
"bytes": 223672,
"gzip9Bytes": 57375
},
"regression": {
"passes": 5,
"timesSeconds": [
0.08,
0.09,
0.07,
0.07,
0.09
],
"medianSeconds": 0.08,
"status": "PASS",
"kernelCount": 19
},
"webGpuBrowserSmoke": {
"status": "UNAVAILABLE_IN_CONTAINER",
"reason": "Headless Chromium SwiftShader/EGL initialization failed before WebGPU could run; no real GPU frame-latency claim is made."
},
"benchmarks": {
"date": "2026-09-29T08:28:46.101Z",
"periodicity": {
"w": 96,
"h": 64,
"maxIter": 8192,
"oracleIter": 65536,
"rows": [
{
"view": "overview",
"productionBackend": "direct",
"pixels": 6144,
"baseWork": 884420,
"heuristicWork": 133404,
"workReduction": 0.849162162773343,
"candidates": 96,
"falseCandidates": 0,
"baseLimit": 104,
"heuristicLimit": 8,
"diagnosticIfForcedDirect": null,
"ms": 68.786555
},
{
"view": "period3-bulb",
"productionBackend": "direct",
"pixels": 6144,
"baseWork": 50331648,
"heuristicWork": 460156,
"workReduction": 0.9908575216929117,
"candidates": 6144,
"falseCandidates": 0,
"baseLimit": 6144,
"heuristicLimit": 0,
"diagnosticIfForcedDirect": null,
"ms": 3092.6467549999998
},
{
"view": "period3-core",
"productionBackend": "direct",
"pixels": 6144,
"baseWork": 50331648,
"heuristicWork": 442395,
"workReduction": 0.991210401058197,
"candidates": 6144,
"falseCandidates": 0,
"baseLimit": 6144,
"heuristicLimit": 0,
"diagnosticIfForcedDirect": null,
"ms": 3061.9720069999994
},
{
"view": "seahorse-boundary",
"productionBackend": "direct",
"pixels": 6144,
"baseWork": 410111,
"heuristicWork": 410111,
"workReduction": 0,
"candidates": 0,
"falseCandidates": 0,
"baseLimit": 0,
"heuristicLimit": 0,
"diagnosticIfForcedDirect": null,
"ms": 17.153881000000183
},
{
"view": "seahorse-deep",
"productionBackend": "fast-extended",
"pixels": 6144,
"baseWork": 36579905,
"heuristicWork": 6167354,
"workReduction": null,
"candidates": 0,
"falseCandidates": 0,
"baseLimit": 4304,
"heuristicLimit": 4304,
"diagnosticIfForcedDirect": {
"workReduction": 0.8314004916087125,
"candidates": 4125,
"falseCandidates": 12
},
"ms": 2289.795112
},
{
"view": "exterior",
"productionBackend": "direct",
"pixels": 6144,
"baseWork": 686432,
"heuristicWork": 137063,
"workReduction": 0.8003254510279241,
"candidates": 72,
"falseCandidates": 0,
"baseLimit": 79,
"heuristicLimit": 7,
"diagnosticIfForcedDirect": null,
"ms": 37.95325000000048
}
],
"note": "Production DIRECT_F32 rule with two attracting-cycle confirmations. FAST/perturbation periodic early-stop is intentionally disabled."
},
"series": {
"rows": [
{
"span": 1e-05,
"jump": 53,
"errorLog2": -22.11596292311006,
"maxAbsError": 7.112067409017996e-09,
"maxRelativeError": 9.415623690713784e-05,
"refLen": 1200,
"buildMs": 32.31590200000028
},
{
"span": 1e-07,
"jump": 446,
"errorLog2": -22.302471602690176,
"maxAbsError": 7.736805567567409e-09,
"maxRelativeError": 0.0031991190750368034,
"refLen": 1200,
"buildMs": 33.50016399999913
},
{
"span": 1e-09,
"jump": 930,
"errorLog2": -22.038152635655024,
"maxAbsError": 7.459933177532973e-09,
"maxRelativeError": 1.015603159369818e-05,
"refLen": 1200,
"buildMs": 29.815043000000514
},
{
"span": 1e-11,
"jump": 1037,
"errorLog2": -23.96377927072575,
"maxAbsError": 2.2791360188558774e-09,
"maxRelativeError": 4.948137247650717e-06,
"refLen": 1200,
"buildMs": 37.88702799999919
}
],
"note": "Production fast-reference worker output. Error compares packed 4th-order series against direct perturbation over 8 screen-domain deltas."
},
"sparseActiveState": {
"rows": [
{
"preset": "fast",
"pixels": 524288,
"activeRatio": 1,
"capacity": 524288,
"oldBytes": 23068672,
"newBytes": 23134208,
"reduction": -0.0028409090909091717
},
{
"preset": "fast",
"pixels": 524288,
"activeRatio": 0.25,
"capacity": 164096,
"oldBytes": 23068672,
"newBytes": 7285760,
"reduction": 0.6841708096590908
},
{
"preset": "fast",
"pixels": 524288,
"activeRatio": 0.1,
"capacity": 65792,
"oldBytes": 23068672,
"newBytes": 2960384,
"reduction": 0.8716708096590909
},
{
"preset": "fast",
"pixels": 524288,
"activeRatio": 0.01,
"capacity": 6810,
"oldBytes": 23068672,
"newBytes": 365176,
"reduction": 0.9841700467196378
},
{
"preset": "standard",
"pixels": 1048576,
"activeRatio": 1,
"capacity": 1048576,
"oldBytes": 46137344,
"newBytes": 46268416,
"reduction": -0.0028409090909091717
},
{
"preset": "standard",
"pixels": 1048576,
"activeRatio": 0.25,
"capacity": 327936,
"oldBytes": 46137344,
"newBytes": 14560256,
"reduction": 0.6844149502840908
},
{
"preset": "standard",
"pixels": 1048576,
"activeRatio": 0.1,
"capacity": 131328,
"oldBytes": 46137344,
"newBytes": 5909504,
"reduction": 0.8719149502840909
},
{
"preset": "standard",
"pixels": 1048576,
"activeRatio": 0.01,
"capacity": 13364,
"oldBytes": 46137344,
"newBytes": 719088,
"reduction": 0.9844141873446378
},
{
"preset": "high",
"pixels": 4194304,
"activeRatio": 1,
"capacity": 4194304,
"oldBytes": 184549376,
"newBytes": 185073664,
"reduction": -0.0028409090909091717
},
{
"preset": "high",
"pixels": 4194304,
"activeRatio": 0.25,
"capacity": 1310976,
"oldBytes": 184549376,
"newBytes": 58207232,
"reduction": 0.6845980557528408
},
{
"preset": "high",
"pixels": 4194304,
"activeRatio": 0.1,
"capacity": 524544,
"oldBytes": 184549376,
"newBytes": 23604224,
"reduction": 0.8720980557528409
},
{
"preset": "high",
"pixels": 4194304,
"activeRatio": 0.01,
"capacity": 52685,
"oldBytes": 184549376,
"newBytes": 2842428,
"reduction": 0.9845980080691251
}
],
"note": "Production allocation: 32 B state + 2x4 B queues + 4 B pixel map per active slot, plus 1-bit membership bitmap. Capacity adds 25% + 256 headroom."
},
"multiReference": {
"maxGuidedPasses": 3,
"w": 64,
"h": 40,
"maxIter": 1200,
"rows": [
{
"view": "seahorse-1e-5",
"grid": 1,
"references": 1,
"total": 2560,
"refEnd": 0,
"mismatchClass": 3,
"mismatchIter": 155,
"mismatchRate": 0.001171875
},
{
"view": "seahorse-1e-5",
"grid": 2,
"references": 5,
"total": 2560,
"refEnd": 0,
"mismatchClass": 3,
"mismatchIter": 155,
"mismatchRate": 0.001171875
},
{
"view": "seahorse-1e-5",
"grid": 3,
"references": 9,
"total": 2560,
"refEnd": 0,
"mismatchClass": 3,
"mismatchIter": 155,
"mismatchRate": 0.001171875
},
{
"view": "seahorse-1e-7",
"grid": 1,
"references": 1,
"total": 2560,
"refEnd": 0,
"mismatchClass": 66,
"mismatchIter": 74,
"mismatchRate": 0.02578125
},
{
"view": "seahorse-1e-7",
"grid": 2,
"references": 5,
"total": 2560,
"refEnd": 0,
"mismatchClass": 37,
"mismatchIter": 41,
"mismatchRate": 0.014453125
},
{
"view": "seahorse-1e-7",
"grid": 3,
"references": 9,
"total": 2560,
"refEnd": 0,
"mismatchClass": 50,
"mismatchIter": 67,
"mismatchRate": 0.01953125
}
],
"note": "CPU f32 perturbation locality surrogate. Production selects up to three additional references from failure clusters instead of fixed grids."
},
"cpuFallback": {
"w": 640,
"h": 360,
"iter": 350,
"threads": 4,
"one": {
"medianMs": 97.22207600000002,
"times": [
115.15600200000154,
86.49102299999868,
97.22207600000002,
97.75022499999977,
95.21002200000112,
105.08147800000006,
81.41742200000044
],
"work": 2658084,
"escaped": 176648,
"operationLimit": 3394,
"heuristicInterior": 1654
},
"multi": {
"medianMs": 36.02884199999971,
"times": [
100.63864199999989,
61.91339699999844,
50.152170999999726,
34.4066870000006,
34.23579900000004,
36.02884199999971,
34.373131000000285
],
"work": 2658084,
"escaped": 176648,
"operationLimit": 3394,
"heuristicInterior": 1654
},
"speedup": 2.698451312978663,
"workMatch": true,
"escapedMatch": true,
"operationLimitMatch": true,
"heuristicMatch": true,
"note": "Production CPU fallback Worker source executed under node:worker_threads shim."
},
"sourceAudit": {
"heuristicClass": true,
"strictDisablesPeriodicity": true,
"seriesBinding": true,
"compactPixelMap": true,
"multiReferencePasses": true,
"cpuFallback": true
},
"environment": {
"node": "v22.16.0",
"cpus": 5,
"platform": "linux",
"arch": "x64"
}
},
"assessment": {
"periodicity": "ADOPT_DIRECT_ONLY",
"seriesApproximation": "ADOPT_EXPERIMENTAL_INTERACTIVE",
"sparseActiveState": "ADOPT",
"dynamicMultiReference": "ADOPT_CAPPED_FAILURE_GUIDED",
"cpuFallback": "ADOPT_COMPATIBILITY_PATH"
}
}