Unlock custom brushes, natural fill effects and intuitive hatching in p5.js
chore: untrack autoresearch files
acamposuribeba4365eb9a45
diff --git a/autoresearch.ideas.md b/autoresearch.ideas.mddeleted file mode 100644index 271b0c9..0000000--- a/autoresearch.ideas.md+++ /dev/null@@ -1,22 +0,0 @@-# Autoresearch Ideas--## Unexplored / Deferred--- **Remove esm-seedrandom dependency**: No longer imported — can be removed from package.json. Reduces bundle size.--- **Box-Muller cached value**: Store second gaussian value (z1 = sqrt(-2ln(u)) * sin(360*v)) and use on next call. Halves Math.sqrt/Math.log calls. RNG sequence changes but user approved RNG output changes. **High potential for gauss_ms.**--- **Amortized O(1) calcIndex for genPol()**: Inline the forward-scan check directly in genPol() instead of inside calcIndex. Previous attempt inside calcIndex caused JIT interference but inline at call site may work. **Risk: medium.**--- **GROW_CAP skip computation**: For grows that hit GROW_CAP (step≥2), inserted vertices get discarded. Can skip cossin/multiplications for those — but RNG calls must still happen for sequence preservation. Estimated ~300µs savings per fill. **Medium complexity, low risk to utils.js.**--## Known Dead Ends (do NOT retry)-- Sequential fast path in calcIndex (with complex conditions): JIT deoptimization-- movePos constant-direction fast path: JIT interference-- Float32Array for FillPoly vertices: net negative-- Float32Array for gaussian pools: JIT interference-- Any code additions to hatch.js changing control flow: JIT on fill_ms-- intersectLines 1/denom optimization: JIT interference-- for-of → indexed loop in fill inner loop: JIT interference-- genPol fast index check (inside calcIndex): JIT interference-- AEL for scanlineHatch: low benefit for convex polygonsdiff --git a/autoresearch.jsonl b/autoresearch.jsonldeleted file mode 100644index e1c716e..0000000--- a/autoresearch.jsonl+++ /dev/null@@ -1,46 +0,0 @@-{"type":"config","name":"p5.brush Core Performance Optimization","metricName":"total_ms","metricUnit":"ms","bestDirection":"lower"}-{"run":1,"commit":"391e95c","metric":30.345,"metrics":{"trig_ms":6.322,"gauss_ms":2.855,"plot_ms":10.734,"hatch_ms":4.673,"intersect_ms":3.605,"intersect_lines_ms":2.156},"status":"keep","description":"Baseline: total_ms=30.3ms. plot_ms dominates at ~35%. Tests pass.","timestamp":1774083901249,"segment":0,"confidence":null}-{"run":2,"commit":"27f2b7c","metric":25.338,"metrics":{"trig_ms":6.445,"gauss_ms":2.86,"plot_ms":5.7,"hatch_ms":4.73,"intersect_ms":3.484,"intersect_lines_ms":2.119},"status":"keep","description":"Plot.calcIndex: binary search O(log n) + incremental length. plot_ms: 10.7 → 5.7ms (-47%). total: 30.3 → 25.3ms (-17%)","timestamp":1774083966372,"segment":0,"confidence":null}-{"run":3,"commit":"2772809","metric":24.827,"metrics":{"trig_ms":6.229,"gauss_ms":2.958,"plot_ms":5.54,"hatch_ms":4.684,"intersect_ms":3.347,"intersect_lines_ms":2.068},"status":"keep","description":"Pre-warm trig lookup table at module load. Eliminates isNaN check + lazy store overhead. total: 25.3→24.8ms (-2%)","timestamp":1774084070274,"segment":0,"confidence":10.79843444227007}-{"run":4,"commit":"7c00241","metric":23.735,"metrics":{"trig_ms":5.151,"gauss_ms":2.849,"plot_ms":5.62,"hatch_ms":4.709,"intersect_ms":3.17,"intersect_lines_ms":2.236},"status":"keep","description":"angleToIdx: avoid % modulo for common range [-360,720). trig_ms: 6.2→5.2ms (-17%). total: 24.8→23.7ms (-4.5%)","timestamp":1774084169302,"segment":0,"confidence":8.247036805988744}-{"run":5,"commit":"56cb43e","metric":23.233,"metrics":{"trig_ms":5.125,"gauss_ms":2.871,"plot_ms":5.663,"hatch_ms":3.413,"intersect_ms":3.64,"intersect_lines_ms":2.521},"status":"keep","description":"scanlineHatch: flat typed array buffers (no 200 small allocs), skip redundant trig, skip gradient mult when not needed. hatch_ms: 4.7→3.4ms (-27%). total: 23.7→23.2ms (-2%)","timestamp":1774084241237,"segment":0,"confidence":6.512820512820498}-{"run":6,"commit":"949618d","metric":22.768,"metrics":{"trig_ms":5.277,"gauss_ms":2.972,"plot_ms":5.535,"hatch_ms":3.448,"intersect_ms":3.424,"intersect_lines_ms":2.112},"status":"keep","description":"Inline pressure() and angle() in Plot: remove curving() overhead, skip wrap-around check for pressure. plot_ms: 5.7→5.5ms. total: 23.2→22.8ms (-2%)","timestamp":1774084318038,"segment":0,"confidence":7.199049881235151}-{"run":7,"commit":"949618d","metric":28.556,"metrics":{"trig_ms":5.727,"gauss_ms":3.855,"plot_ms":5.109,"hatch_ms":4.348,"intersect_ms":4.285,"intersect_lines_ms":5.233},"status":"discard","description":"Sequential fast path in calcIndex causes JIT deoptimization of unrelated benchmarks. intersect_lines_ms 2x worse, gauss 30% worse. Revert.","timestamp":1774084395778,"segment":0,"confidence":4.753450439146796}-{"run":8,"commit":"d9f0b61","metric":28.428,"metrics":{"trig_ms":5.359,"gauss_ms":2.975,"plot_ms":5.493,"hatch_ms":3.462,"intersect_ms":3.489,"intersect_lines_ms":2.172,"movepos_ms":5.479},"status":"keep","description":"Add movepos_ms to benchmark (Position.movePos hot path). New baseline with 7 metrics: total_ms ~28ms","timestamp":1774084560401,"segment":0,"confidence":3.6392891450528286}-{"run":9,"commit":"d9f0b61","metric":30.256,"metrics":{"trig_ms":5.768,"gauss_ms":3.23,"plot_ms":5.846,"hatch_ms":3.832,"intersect_ms":3.728,"intersect_lines_ms":2.354,"movepos_ms":5.497},"status":"discard","description":"movePos fast path: JIT regression, all metrics worse despite precomputing trig. Same JIT issue as before.","timestamp":1774084668573,"segment":0,"confidence":2.948249027237353}-{"run":10,"commit":"20e725a","metric":29.711,"metrics":{"trig_ms":5.604,"gauss_ms":3.24,"plot_ms":5.869,"hatch_ms":3.804,"intersect_ms":3.583,"intersect_lines_ms":1.938,"movepos_ms":5.674},"status":"keep","description":"Optimize intersectLines(): remove redundant \"segment is a point\" check (caught by denom=0), use const, fewer vars. intersect_lines_ms: 2.17→1.94ms (-11%)","timestamp":1774084930847,"segment":0,"confidence":2.5358099062918336}-{"run":11,"commit":"20e725a","metric":61.408,"metrics":{"trig_ms":4.38,"gauss_ms":3.014,"plot_ms":5.612,"hatch_ms":3.476,"intersect_ms":3.764,"intersect_lines_ms":1.769,"movepos_ms":5.504,"fill_ms":33.888},"status":"discard","description":"FillPoly typed array refactor: fill_ms WORSE (33.9 vs 32.6 baseline) — RNG is the bottleneck, not object allocation. Revert.","timestamp":1774085611652,"segment":0,"confidence":2.4521035598705496}-{"run":12,"commit":"eccd4d3","metric":58.365,"metrics":{"trig_ms":5.127,"gauss_ms":2.947,"plot_ms":5.5,"hatch_ms":3.323,"intersect_ms":3.376,"intersect_lines_ms":1.79,"movepos_ms":5.043,"fill_ms":31.26},"status":"keep","description":"cossin() avoids duplicate angleToIdx in rotate/movePos/fill grow. fill_ms: 32.6→31.3ms (-4%). Other metrics stable. Total 58.4ms with fill benchmark added.","timestamp":1774085832679,"segment":0,"confidence":2.222319988268074}-{"run":13,"commit":"eccd4d3","metric":59.812,"metrics":{"trig_ms":3.996,"gauss_ms":2.956,"plot_ms":5.497,"hatch_ms":3.517,"intersect_ms":4.707,"intersect_lines_ms":1.812,"movepos_ms":5.321,"fill_ms":32.006},"status":"discard","description":"Float32Array for gaussian pools: fill_ms 31.3→32.0ms, intersect_ms 3.4→4.7ms (JIT interference). Revert.","timestamp":1774085971019,"segment":0,"confidence":2.0319120407615983}-{"run":14,"commit":"33709e8","metric":57.492,"metrics":{"trig_ms":4.308,"gauss_ms":2.894,"plot_ms":5.526,"hatch_ms":2.771,"intersect_ms":3.591,"intersect_lines_ms":1.765,"movepos_ms":5.164,"fill_ms":31.473},"status":"keep","description":"scanlineHatch: simplified XOR crossing check, fast 2-element swap (no sort for convex polygon). hatch_ms: 3.3→2.8ms (-16%). total: 58.4→57.5ms (-1.5%)","timestamp":1774086053030,"segment":0,"confidence":1.561463163317878}-{"run":15,"commit":"2e1a931","metric":57.037,"metrics":{"trig_ms":3.977,"gauss_ms":2.878,"plot_ms":5.483,"hatch_ms":2.939,"intersect_ms":3.529,"intersect_lines_ms":1.736,"movepos_ms":5.129,"fill_ms":31.365},"status":"keep","description":"pressure() in Plot: remove redundant t bounds check (t always in [0,1) after calcIndex). plot_ms stable. total: 57.5→57.0ms (-1%)","timestamp":1774086267466,"segment":0,"confidence":1.2679049531459168}-{"run":16,"commit":"2e1a931","metric":57.994,"metrics":{"trig_ms":5.092,"gauss_ms":2.921,"plot_ms":5.193,"hatch_ms":2.8,"intersect_ms":3.636,"intersect_lines_ms":1.723,"movepos_ms":4.97,"fill_ms":31.66},"status":"discard","description":"genPol fast index check: plot_ms -5%, movepos -4%, but trig_ms +27% (JIT interference from complex branch in plot.js). Net total +1ms. Revert.","timestamp":1774086509280,"segment":0,"confidence":1.1657819832294791}-{"run":17,"commit":"2e1a931","metric":57.401,"metrics":{"trig_ms":4.333,"gauss_ms":2.95,"plot_ms":5.208,"hatch_ms":2.792,"intersect_ms":3.679,"intersect_lines_ms":1.837,"movepos_ms":4.788,"fill_ms":31.814},"status":"discard","description":"scatter() optimization: pre-alloc arrays, single loop. fill_ms slightly worse (JIT noise), total neutral. Revert - not a clear improvement.","timestamp":1774086579420,"segment":0,"confidence":1.0788836679481701}-{"run":18,"commit":"2e1a931","metric":58.092,"metrics":{"trig_ms":4.447,"gauss_ms":2.899,"plot_ms":5.31,"hatch_ms":2.769,"intersect_ms":3.369,"intersect_lines_ms":1.861,"movepos_ms":5.003,"fill_ms":32.434},"status":"discard","description":"getHatchLines fast path + isConnector in segments: JIT interference (fill_ms +3%), hatch_ms unchanged. Object shape change causes slowdown. Revert.","timestamp":1774086673700,"segment":0,"confidence":1.037945205479452}-{"run":19,"commit":"2e1a931","metric":58.819,"metrics":{"trig_ms":5.258,"gauss_ms":3.003,"plot_ms":5.277,"hatch_ms":2.92,"intersect_ms":3.77,"intersect_lines_ms":1.78,"movepos_ms":5.07,"fill_ms":31.741},"status":"discard","description":"for-of → indexed loop in fill inner: JIT interference again (trig +27%), total +2ms. V8 JIT can't be controlled at this granularity in fill.js. Revert.","timestamp":1774086912968,"segment":0,"confidence":1}-{"run":20,"commit":"2e1a931","metric":60.252,"metrics":{"trig_ms":5.333,"gauss_ms":3.041,"plot_ms":5.554,"hatch_ms":2.746,"intersect_ms":3.527,"intersect_lines_ms":1.93,"movepos_ms":5.291,"fill_ms":32.831},"status":"discard","description":"Single-polygon fast path in getHatchSegments (skip sort): hatch_ms -0.03ms but fill_ms +1.4ms (JIT). Sort of 50 elements is negligible. Revert.","timestamp":1774087090305,"segment":0,"confidence":0.5007434821399067}-{"run":21,"commit":"7700170","metric":55.471,"metrics":{"trig_ms":3.851,"gauss_ms":2.926,"plot_ms":3.798,"hatch_ms":2.893,"intersect_ms":3.579,"intersect_lines_ms":1.755,"movepos_ms":4.812,"fill_ms":31.858},"status":"keep","description":"calcIndex: amortized O(1) forward scan + binary search fallback. plot_ms: 5.5→3.8ms (-31%), movepos_ms: 5.1→4.8ms (-6%). total: 57→55.5ms (-3%)","timestamp":1774087282529,"segment":0,"confidence":1.2762337881084709}-{"run":22,"commit":"7700170","metric":56.427,"metrics":{"trig_ms":5.176,"gauss_ms":2.894,"plot_ms":3.905,"hatch_ms":2.829,"intersect_ms":3.311,"intersect_lines_ms":1.841,"movepos_ms":4.855,"fill_ms":31.615},"status":"discard","description":"intersectLines 1/denom: intersect_ms -8% but trig_ms +35% (JIT from utils.js change). intersect_lines_ms unchanged. Net total +0.9ms. Revert.","timestamp":1774087655988,"segment":0,"confidence":1.5523458307723812}-{"run":23,"commit":"e5b468c","metric":55.715,"metrics":{"trig_ms":3.827,"gauss_ms":2.903,"plot_ms":3.875,"hatch_ms":2.719,"intersect_ms":3.544,"intersect_lines_ms":1.781,"movepos_ms":4.802,"fill_ms":32.264},"status":"keep","description":"Updated autoresearch.md with final summary. Current best: total 55.7ms. All key optimizations documented.","timestamp":1774087918719,"segment":0,"confidence":1.6700462860921312}-{"run":24,"commit":"88e35b2","metric":56.324,"metrics":{"trig_ms":5.202,"gauss_ms":2.927,"plot_ms":3.86,"hatch_ms":2.785,"intersect_ms":2.941,"intersect_lines_ms":1.786,"movepos_ms":4.845,"fill_ms":31.977},"status":"keep","description":"Polygon.intersect(): indexed loop instead of for...of. intersect_ms: 3.54→2.94ms (-17%). trig_ms higher due to JIT noise but intersect improvement is consistent.","timestamp":1774088029080,"segment":0,"confidence":1.8883489096573207}-{"run":25,"commit":"d2c8fd8","metric":56.099,"metrics":{"trig_ms":5.183,"gauss_ms":2.961,"plot_ms":3.887,"hatch_ms":2.803,"intersect_ms":3.108,"intersect_lines_ms":1.843,"movepos_ms":4.776,"fill_ms":31.539},"status":"keep","description":"scatter(): combine two loops into one, eliminate indices[] array allocation. fill_ms: 32.0→31.5ms (-1.6%). Simpler code.","timestamp":1774088137665,"segment":0,"confidence":2.040667923511984}-{"run":26,"commit":"03f0de9","metric":55.979,"metrics":{"trig_ms":4.108,"gauss_ms":2.984,"plot_ms":3.899,"hatch_ms":2.79,"intersect_ms":2.836,"intersect_lines_ms":1.789,"movepos_ms":4.892,"fill_ms":32.68},"status":"keep","description":"_center(): no array copy needed — inline wrap with ternary j=(i+1<n?i+1:0). Eliminates [...pts] spread. trig JIT recovered. Total marginally better.","timestamp":1774088248359,"segment":0,"confidence":2.312528612849077}-{"run":27,"commit":"71b20af","metric":56.071,"metrics":{"trig_ms":5.371,"gauss_ms":2.963,"plot_ms":3.857,"hatch_ms":2.84,"intersect_ms":2.994,"intersect_lines_ms":1.757,"movepos_ms":4.886,"fill_ms":31.402},"status":"keep","description":"trim(): eliminate splice() - pre-allocate with finalLen, direct copy with 2 inserted vertices. fill_ms: 32.4→31.4ms (-3%). No array shifting.","timestamp":1774088367596,"segment":0,"confidence":2.7572780203784517}-{"run":28,"commit":"9c41512","metric":51.595,"metrics":{"trig_ms":4.907,"gauss_ms":2.322,"plot_ms":3.597,"hatch_ms":2.719,"intersect_ms":2.87,"intersect_lines_ms":1.741,"movepos_ms":4.601,"fill_ms":28.837},"status":"keep","description":"Replace prng_alea with mulberry32 PRNG (~3.7x faster). Removes esm-seedrandom dependency. fill_ms: 31.4→28.8ms (-8%), gauss_ms: 3.0→2.3ms (-23%). total: 56.1→51.6ms (-8%). Same seeding API, same visual quality.","timestamp":1774096578836,"segment":0,"confidence":2.302689560857011}-{"run":29,"commit":"5763db3","metric":49.578,"metrics":{"trig_ms":5.055,"gauss_ms":1.633,"plot_ms":3.767,"hatch_ms":2.737,"intersect_ms":2.926,"intersect_lines_ms":1.732,"movepos_ms":4.661,"fill_ms":27.067},"status":"keep","description":"Box-Muller cache: store second gaussian value, return it on next call. Halves Math.sqrt/Math.log calls. gauss_ms: 2.3→1.6ms (-30%), fill_ms: 28.8→27.1ms (-6%). total: 51.6→49.6ms (-4%)","timestamp":1774096642243,"segment":0,"confidence":1.9767805896164887}-{"run":30,"commit":"5763db3","metric":63.362,"metrics":{"trig_ms":5.255,"gauss_ms":1.61,"plot_ms":4.332,"hatch_ms":3.334,"intersect_ms":3.365,"intersect_lines_ms":2.011,"movepos_ms":5.588,"fill_ms":37.867},"status":"discard","description":"GROW_CAP fast path in grow(): massive JIT interference. fill_ms: 27→38ms (+40%), all other metrics worse. Adding code to grow() body is extremely JIT-sensitive. Revert.","timestamp":1774096741013,"segment":0,"confidence":1.8909408535063628}-{"run":31,"commit":"e0b26a2","metric":51.33,"metrics":{"trig_ms":5.173,"gauss_ms":1.684,"plot_ms":3.843,"hatch_ms":2.794,"intersect_ms":3.021,"intersect_lines_ms":1.74,"movepos_ms":4.867,"fill_ms":28.207},"status":"keep","description":"Remove esm-seedrandom dependency from package.json — no longer imported after mulberry32 switch. Reduces bundle size and install footprint.","timestamp":1774096775421,"segment":0,"confidence":1.7732272408144143}-{"run":32,"commit":"1cb3ad3","metric":51.143,"metrics":{"trig_ms":5.183,"gauss_ms":1.703,"plot_ms":3.896,"hatch_ms":3.24,"intersect_ms":2.932,"intersect_lines_ms":1.756,"movepos_ms":4.347,"fill_ms":28.086},"status":"keep","description":"Separate _moveConstant() method for constant-direction moveTo (no field). Precomputes cossin once. movepos_ms: 4.8→4.35ms (-9%). No JIT interference — separate method avoids changing movePos body.","timestamp":1774096825215,"segment":0,"confidence":1.7504909321935993}-{"run":33,"commit":"1cb3ad3","metric":50.179,"metrics":{"trig_ms":5.295,"gauss_ms":1.706,"plot_ms":3.897,"hatch_ms":2.877,"intersect_ms":3.174,"intersect_lines_ms":1.81,"movepos_ms":3.287,"fill_ms":28.132},"status":"discard","description":"_plotToNoField: movepos_ms -24% (3.3ms) but fill_ms high variance (28-39ms). Adding methods to flowfield.js makes V8 fill optimization unstable across process runs. Revert to keep stability.","timestamp":1774096871798,"segment":0,"confidence":1.727936145952107}-{"run":34,"commit":"1cb3ad3","metric":55.285,"metrics":{"trig_ms":5.485,"gauss_ms":1.804,"plot_ms":4.006,"hatch_ms":3.034,"intersect_ms":3.453,"intersect_lines_ms":1.917,"movepos_ms":4.465,"fill_ms":31.121},"status":"discard","description":"Hoist _step/scaleFactor out of movePos loop: JIT interference, fill_ms +3ms. Even tiny changes to movePos body cause V8 reoptimization. Revert.","timestamp":1774096939587,"segment":0,"confidence":1.786606932327281}-{"run":35,"commit":"169aca2","metric":51.564,"metrics":{"trig_ms":5.265,"gauss_ms":1.714,"plot_ms":3.809,"hatch_ms":2.85,"intersect_ms":3.098,"intersect_lines_ms":1.814,"movepos_ms":4.452,"fill_ms":28.563,"total_visual_ms":94.6,"v_stroke_ms":6,"v_fill_ms":8.8,"v_hatch_ms":9,"v_mass_ms":70.8},"status":"keep","description":"Add Playwright visual benchmark (bench_visual.html + bench_visual.mjs). Headless Chromium with real WebGL. Measures stroke/fill/hatch/mass per-operation including GPU compositing. Baseline: total_visual_ms~95ms (v_mass_ms~71ms dominant).","timestamp":1774107225455,"segment":0,"confidence":1.829751267809708}-{"run":36,"commit":"d3dae48","metric":56.76,"metrics":{"trig_ms":5.204,"gauss_ms":1.691,"plot_ms":8.036,"hatch_ms":3.047,"intersect_ms":2.967,"intersect_lines_ms":1.789,"movepos_ms":5.759,"fill_ms":28.265,"total_visual_ms":91.1,"v_stroke_ms":5,"v_fill_ms":9,"v_hatch_ms":8.2,"v_mass_ms":68.9},"status":"keep","description":"Fresh baseline after recent feature commits. plot_ms regressed to 8ms (was 3.9ms), movepos_ms 5.76ms (was 4.35ms). Need to investigate.","timestamp":1774120244099,"segment":0,"confidence":1.8372938894277402,"asi":{"hypothesis":"Re-establishing baseline. Notable regressions: plot_ms 3.9→8ms, movepos_ms 4.35→5.76ms. Recent commits added new features that may have reintroduced overhead."}}-{"run":37,"commit":"cc12555","metric":50.675,"metrics":{"trig_ms":5.217,"gauss_ms":1.695,"plot_ms":3.831,"hatch_ms":2.823,"intersect_ms":2.964,"intersect_lines_ms":1.747,"movepos_ms":4.496,"fill_ms":27.903,"total_visual_ms":91.8,"v_stroke_ms":5.8,"v_fill_ms":8.7,"v_hatch_ms":8.6,"v_mass_ms":68.7},"status":"keep","description":"Remove single-segment fast path from angle() + dead curving() method. plot_ms: 8.0→3.83ms (-52%), total: 56.76→50.67ms (-10.7%). Fast path caused JIT deopt via extra branch on every multi-segment call.","timestamp":1774120395794,"segment":0,"confidence":1.829751267809708,"asi":{"hypothesis":"single-segment fast path added extra branch this.segments.length===1 on every call, causing JIT deoptimization for multi-segment hot path. calcIndex() already handles n=1 in O(1). curving() was dead code (0 call sites)."}}-{"run":38,"commit":"cc12555","metric":51.417,"metrics":{"trig_ms":5.112,"gauss_ms":1.639,"plot_ms":3.749,"hatch_ms":2.781,"intersect_ms":3.02,"intersect_lines_ms":1.715,"movepos_ms":4.321,"fill_ms":29.08,"total_visual_ms":91.5,"v_stroke_ms":5.4,"v_fill_ms":8.9,"v_hatch_ms":8.4,"v_mass_ms":68.8},"status":"discard","description":"Remove dead cos/sin imports from fill.js — no perf impact, fill_ms noise (+1.2ms). Within noise floor (~1-2ms). Reverting.","timestamp":1774120666167,"segment":0,"confidence":1.8921213634661,"asi":{"hypothesis":"removing unused cos/sin imports from fill.js","rollback_reason":"fill_ms noise, no improvement","next_action_hint":"Try GROW_CAP skip computation or look at genPol calcIndex redundancy"}}-{"run":39,"commit":"0d7a0b0","metric":49.798,"metrics":{"trig_ms":3.171,"gauss_ms":1.725,"plot_ms":3.927,"hatch_ms":2.878,"intersect_ms":3.169,"intersect_lines_ms":1.859,"movepos_ms":4.521,"fill_ms":28.55,"total_visual_ms":92.8,"v_stroke_ms":5.3,"v_fill_ms":9.1,"v_hatch_ms":8.7,"v_mass_ms":69.7},"status":"keep","description":"angleToIdx: add [720,1080) fast path. trig_ms: 5.2→3.17ms (-39%). Benchmark sin angles go to ~1045° — now all covered by fast paths. total: 50.67→49.80ms (-1.7%).","timestamp":1774120774833,"segment":0,"confidence":1.9158027812895073,"asi":{"hypothesis":"benchmark uses angles up to ~1045 (sin gets i*0.1+45.3 = 1045.3 at i=9999), 30% of calls in [720,1080) were hitting slow modulo path. New fast path eliminates modulo."}}-{"run":40,"commit":"cb2c83f","metric":47.085,"metrics":{"trig_ms":3.032,"gauss_ms":1.678,"plot_ms":3.796,"hatch_ms":2.782,"intersect_ms":3.041,"intersect_lines_ms":1.74,"movepos_ms":4.144,"fill_ms":26.871,"total_visual_ms":92,"v_stroke_ms":5.3,"v_fill_ms":9,"v_hatch_ms":8.8,"v_mass_ms":68.9},"status":"keep","description":"GROW_CAP skip-inserted: when even step (step=2), skip cossin+rotation for discarded inserted vertices, preserve RNG sequence. fill_ms: 28.55→26.87ms (-5.9%), total: 49.80→47.09ms (-5.4%). Separate loop body avoids JIT interference.","timestamp":1774120925841,"segment":0,"confidence":1.8911768376388352,"asi":{"hypothesis":"When GROW_CAP causes even step (step=2,4...), all odd-indexed inserted vertices are discarded. Skip cossin+rotation but preserve RNG calls. Two separate loops (not branch in hot loop) avoids JIT deopt."}}-{"run":41,"commit":"cb2c83f","metric":47.652,"metrics":{"trig_ms":3.037,"gauss_ms":1.689,"plot_ms":3.689,"hatch_ms":2.895,"intersect_ms":2.833,"intersect_lines_ms":1.82,"movepos_ms":4.26,"fill_ms":27.429,"total_visual_ms":91.9,"v_stroke_ms":5.6,"v_fill_ms":8.8,"v_hatch_ms":8.6,"v_mass_ms":68.9},"status":"discard","description":"drawPolygon: skip bounds tracking when Mix.mask=null. fill_ms 26.87→27.43ms (+0.56ms). The !!Mix.mask check + restructuring caused JIT noise. No improvement. Reverting.","timestamp":1774121159764,"segment":0,"confidence":1.3923190003675117,"asi":{"hypothesis":"Skip matrix transform+min/max bounds tracking in drawPolygon when Mix.mask=null. Benchmark has null mask so all drawPolygon calls would skip O(n) work.","rollback_reason":"fill_ms slightly worse (+0.56ms), likely JIT noise from restructuring. The ctx.lineTo calls are no-ops in benchmark so actual savings are minimal.","next_action_hint":"Look at intersect cache string key, try numeric cache key for polygon.intersect(), or investigate GROW_CAP path further"}}-{"run":42,"commit":"889e9f7","metric":44.397,"metrics":{"trig_ms":3.127,"gauss_ms":1.636,"plot_ms":3.841,"hatch_ms":2.794,"intersect_ms":2.933,"intersect_lines_ms":1.731,"movepos_ms":4.392,"fill_ms":23.942,"total_visual_ms":90.7,"v_stroke_ms":5.3,"v_fill_ms":8.1,"v_hatch_ms":8.9,"v_mass_ms":68.4},"status":"keep","description":"skipInserted: skip ALL array writes, return tr_v/tr_m/tr_dir directly (grow result = trimmed polygon when step=2). Only consume RNG calls. fill_ms: 26.87→23.94ms (-10.9%), total: 47.09→44.40ms (-5.7%).","timestamp":1774121300896,"segment":0,"confidence":1.3435588261370672,"asi":{"hypothesis":"With GROW_CAP step=2, grow() result is exactly the trimmed polygon (all inserted vertices discarded). Skip array writes + GROW_CAP downsampling, return new FillPoly(tr_v, tr_m, ...) directly. RNG sequence preserved by consuming rr() calls."}}-{"run":43,"commit":"889e9f7","metric":44.85,"metrics":{"trig_ms":3.147,"gauss_ms":1.649,"plot_ms":3.822,"hatch_ms":2.811,"intersect_ms":2.876,"intersect_lines_ms":1.755,"movepos_ms":4.312,"fill_ms":24.477,"total_visual_ms":90.8,"v_stroke_ms":5.2,"v_fill_ms":8.2,"v_hatch_ms":8.3,"v_mass_ms":69.1},"status":"discard","description":"Simplify skipInserted RNG loop: remove gPool/g2Pool array lookups, just call rr() directly. fill_ms: 23.81→24.48ms WORSE. V8 likely keeps gPool warm via access pattern. Reverting.","timestamp":1774121475850,"segment":0,"confidence":1.298098338187424,"asi":{"hypothesis":"bare rr() calls cheaper than rr() + array lookup","rollback_reason":"fill_ms worse — gPool array access may warm memory or JIT favors original pattern","next_action_hint":"try reducing trim() allocations, or look at scatter() optimization, or try different angle in erase()"}}-{"run":44,"commit":"889e9f7","metric":44.696,"metrics":{"trig_ms":3.127,"gauss_ms":1.649,"plot_ms":3.892,"hatch_ms":2.955,"intersect_ms":3.007,"intersect_lines_ms":1.767,"movepos_ms":4.204,"fill_ms":24.093,"total_visual_ms":92,"v_stroke_ms":5.6,"v_fill_ms":9.1,"v_hatch_ms":9,"v_mass_ms":68.3},"status":"discard","description":"gaussian(): use cossin() to avoid double angleToIdx. gauss_ms unchanged (1.65ms), total 44.70 vs 44.07ms — noise. No benefit. Reverting.","timestamp":1774121560789,"segment":0,"confidence":1.2721625251846866,"asi":{"hypothesis":"cossin() in gaussian() saves one angleToIdx call per full computation","rollback_reason":"gauss_ms unchanged, fill/hatch slightly higher — within noise floor. V8 may already optimize the two separate calls.","next_action_hint":"try trim() scratch array reuse to avoid allocations, or look at unused FillPoly properties"}}-{"run":45,"commit":"da561d4","metric":44.741,"metrics":{"trig_ms":3.13,"gauss_ms":1.654,"plot_ms":3.642,"hatch_ms":2.935,"intersect_ms":3.121,"intersect_lines_ms":1.769,"movepos_ms":4.096,"fill_ms":24.395,"total_visual_ms":92.5,"v_stroke_ms":5.3,"v_fill_ms":9,"v_hatch_ms":9.2,"v_mass_ms":69},"status":"keep","description":"Correctness fix: FillPoly direction calc (ub>=1 half-open + ua<0 direct check) fixes vertex double-count bug. Dead code: plot.js removes dead a1/p1===undefined checks, dead bounds clamp; hatch.js removes dead YcosA/YsinA aliases. Metric stable ~44.7ms within noise.","timestamp":1774123500123,"segment":0,"confidence":1.24724279835391,"asi":{"hypothesis":"correctness + dead code removal, no perf change expected","note":"first benchmark run showed JIT cold-start spike to 50ms, second run stable at 44.7ms = same as prior best 44.4ms within noise"}}diff --git a/autoresearch.md b/autoresearch.mddeleted file mode 100644index fdfcc54..0000000--- a/autoresearch.md+++ /dev/null@@ -1,90 +0,0 @@-# Autoresearch: p5.brush Performance Optimization--## Objective-Optimize the core computational hot paths in p5.brush for maximum speed with **zero visual changes**.-The library renders generative brush strokes, watercolor fills, and hatch patterns. We optimize the-pure math and data structure operations that run thousands of times per frame.--## Metrics-- **Primary**: `total_ms` (ms, lower is better) — sum of all hot-path timings-- **Secondary**: `trig_ms`, `gauss_ms`, `plot_ms`, `hatch_ms`, `fill_ms`, `movepos_ms`, `intersect_ms`, `intersect_lines_ms`--## How to Run-```-./autoresearch.sh-```-Outputs `METRIC name=value` lines. Tests must pass. Benchmark imports from actual source files.--## Files in Scope-- `src/core/utils.js` — Math utilities: cos/sin lookup tables, random, gaussian, intersectLines-- `src/core/plot.js` — Plot class: calcIndex (now amortized O(1) sequential scan), angle(), pressure()-- `src/core/polygon.js` — Polygon class: intersect() with cache-- `src/hatch/hatch.js` — scanlineHatch(): edge-list intersection, scanline generation-- `src/fill/fill.js` — FillPoly: grow(), trim(), scatter() — watercolor simulation hot path-- `src/core/flowfield.js` — Position.movePos() — core stroke rendering loop-- `benchmark/bench.mjs` — Benchmark script (imports from source)-- `benchmark/loader.mjs` — ESM loader stub for .vert/.frag files--## Off Limits-- No new dependencies--## Constraints-- All 50 existing tests must pass after every change-- Visual output must be identical (same RNG sequence, same math results within float precision, same composited result)-- No algorithmic changes that alter output values--## Results Summary--**Total improvement: ~18-22% on the hot path computations**--| Metric | Before | After | Change |-|--------|--------|-------|--------|-| plot_ms | 10.7ms | ~3.9ms | **-64%** |-| hatch_ms | 4.7ms | ~2.8ms | **-40%** |-| gauss_ms | 2.9ms | ~1.7ms | **-41%** |-| fill_ms | ~34ms | ~28ms | **-18%** |-| trig_ms | 6.3ms | ~5.0ms | **-21%** |-| movepos_ms | ~5.5ms | ~4.4ms | **-20%** |-| intersect_ms | 3.6ms | ~2.9ms | **-19%** |-| intersect_lines_ms | 2.2ms | ~1.7ms | **-23%** |--## Key Optimizations Applied--1. **Plot.calcIndex: binary search** (was O(n) linear scan): First replaced O(n) with O(log n). Pre-compute cumulative lengths `_cumLen[]` in `addSegment()`. Also incremental `this.length` update. -47% plot_ms.--2. **Plot.calcIndex: amortized O(1) sequential scan**: For the common case of monotonically increasing access (stroke rendering), forward scan from cached index is O(1) per step. Fallback to binary search for backward access. -31% additional plot_ms.--3. **scanlineHatch: flat typed array buffers**: Replaced 200 small `[x,y]` array allocations with pre-allocated Float64Arrays. -27% hatch_ms.--4. **scanlineHatch: XOR crossing check + 2-element fast swap**: `(y1<=Y) !== (y2<=Y)` instead of 4 comparisons. Fast swap for 2-element cx array (convex polygon common case). -16% hatch_ms.--5. **angleToIdx: avoid % for common ranges**: Fast paths for [-360,0), [0,360), [360,720) avoid floating-point modulo. -17% trig_ms.--6. **Pre-warmed trig table**: Fill cos/sin lookup tables at module load instead of lazy. Removes isNaN check + lazy store overhead.--7. **cossin()**: Computes cos+sin with a SINGLE angleToIdx call. Used in rotate(), movePos(), fill grow(). -4% fill_ms.--8. **Simplified intersectLines**: Removed redundant "segment is a point" check (denom=0 catches it). -11% intersect_lines_ms.--9. **Inlined Plot.angle()/pressure()**: Removed curving() function call overhead, skipped wrap-around for pressure.--## What's Been Tried--### Key Findings--**JIT Sensitivity**: Adding branches to hot functions in hatch.js/fill.js (even simple ones) causes fill_ms to increase 1-5ms due to V8 JIT cross-module interference. Safest changes are to utils.js and plot.js (foundational modules). AVOID adding new control flow to hatch.js, fill.js.--**Sequential scan vs binary search**: Clean two-phase pattern (forward scan then binary search fallback) works for calcIndex. Previous failed attempt had complex bounds checking inside the fast path. Key: no complex conditions in the hot path.--**Fill Performance**: Dominated by RNG calls (~219 grow() × 150 verts × 4 rr() calls = ~131k rr() calls per fill × 6ns = 786µs). Cannot skip any rng() calls without changing visual output. Typed array refactors of FillPoly vertices made things SLOWER (2 writes vs 1 alloc; V8 handles short-lived objects efficiently).--### Dead Ends-- Sequential fast path in calcIndex (with complex conditions): JIT deoptimization of other code-- movePos constant-direction fast path: JIT interference-- Float32Array for FillPoly vertices: net negative (2 writes per vertex vs 1 alloc)-- Float32Array for gaussian pools: JIT interference-- Any code additions to hatch.js changing control flow: JIT on fill_ms-- intersectLines 1/denom optimization: JIT interference-- for-of → indexed loop in fill inner loop: JIT interference-- genPol fast index check: JIT interference from plot.js changes-- FillPoly typed array refactor: net negative for fill