[2b] Replace per-pixel ImageData fill loop with Uint32Array view (3-5x speedup)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- javascript
- Domain
- frontend, performance
Research direction
Start by reading the gray-to-RGBA loops in src/ARFset.js:131-137 and js/arfset.api.js:101-107, then compare their buffer layout with the replacement pattern in the issue. Refactor both loops to write through a Uint32Array view, and verify that grayscale rendering remains unchanged while the conversion uses one 32-bit write per pixel.
Written by the indexing model from the issue text.
Description
Summary
Replace slow per-pixel ImageData fill loop with Uint32Array view for 3–5× speedup
Environment
- Product/Service: FeatureSET-Display — JavaScript API
- Files:
src/ARFset.js:131-137,js/arfset.api.js:101-107
Problem Description
Both files contain a for (i, j) { id.data[j+0..2] = v; id.data[j+3] = 255 } loop that fills grayscale pixels into an RGBA ImageData buffer one channel at a time. Writing to Uint8ClampedArray four bytes per pixel is significantly slower than writing a Uint32Array view of the same buffer one 32-bit word per pixel.
Expected Behavior
Gray → RGBA conversion uses a Uint32Array view of id.data and writes each pixel as a single 32-bit word: (0xff000000 | v<<16 | v<<8 | v), giving a 3–5× throughput improvement.
Actual Behavior
Each pixel writes four separate bytes to a Uint8ClampedArray, leaving significant CPU performance on the table.
Tasks
- Refactor the gray → RGBA conversion loop in
src/ARFset.js:131-137using aUint32Arrayview - Apply the same refactor to
js/arfset.api.js:101-107
Impact
Low / Performance — No functional change; improves rendering throughput, particularly noticeable at high resolutions or frame rates.
Additional Context
Replacement pattern:
const pixels = new Uint32Array(id.data.buffer);
for (let i = 0; i < pixels.length; i++) {
const v = grayData[i];
pixels[i] = (0xff000000 | v << 16 | v << 8 | v);
}
Small, self-contained change. Good candidate to land alongside 2a and 2c.
- Dominant language
- JavaScript
- Stars
- 8
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from webarkit/FeatureSET-Display
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 58/100
All issues in webarkit/FeatureSET-Display
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·