Skip to content

Commit 8217ea4

Browse files
committed
refactor(core): Optimize fiber data processing
1 parent fe12b7d commit 8217ea4

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,10 @@ We expect all contributors to abide by the terms of our [Code of Conduct](https:
246246
- [ ] "PageSpeed insights" for React
247247
- [ ] Offscreen canvas on worker thread
248248
- [ ] React Native support
249-
- [ ] Name / explain the actual problem
249+
- [ ] Name / explain the actual problem, docs
250250
- [ ] Simple FPS counter
251251
- [ ] Drag and select areas of the screen to scan
252+
- [ ] Long task progress bar filter
252253
- [ ] Add a funny mascot, like the ["Stop I'm Changing" dude](https://www.youtube.com/shorts/FwOZdX7bDKI?app=desktop)
253254

254255
## Acknowledgments

src/core/index.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,6 @@ export const start = () => {
193193
playGeigerClickSound(audioContext, amplitude);
194194
}
195195

196-
const fiberData = ReactScanInternals.fiberMap.get(fiber);
197-
const now = Date.now();
198-
let count = render.count;
199-
let time = render.time;
200-
if (fiberData) {
201-
// clear aggregated fibers after 5 seconds
202-
if (now - fiberData.lastUpdated > (options.resetCountTimeout ?? 5000)) {
203-
ReactScanInternals.fiberMap.delete(fiber);
204-
} else {
205-
count += fiberData.count;
206-
time += fiberData.time;
207-
render.count = count;
208-
render.time = time;
209-
}
210-
}
211-
212196
if (render.name) {
213197
const prev = ReactScanInternals.reportData[render.name];
214198
ReactScanInternals.reportData[render.name] = {
@@ -217,14 +201,33 @@ export const start = () => {
217201
};
218202
}
219203

220-
ReactScanInternals.fiberMap.set(fiber, {
221-
count,
222-
time,
223-
lastUpdated: now,
224-
});
225-
226204
requestAnimationFrame(() => {
227205
flushOutlines(ctx, new Map(), toolbar, perfObserver);
206+
207+
const fiberData = ReactScanInternals.fiberMap.get(fiber);
208+
const now = Date.now();
209+
let count = render.count;
210+
let time = render.time;
211+
if (fiberData) {
212+
// clear aggregated fibers after 5 seconds
213+
if (
214+
now - fiberData.lastUpdated >
215+
(options.resetCountTimeout ?? 5000)
216+
) {
217+
ReactScanInternals.fiberMap.delete(fiber);
218+
} else {
219+
count += fiberData.count;
220+
time += fiberData.time;
221+
render.count = count;
222+
render.time = time;
223+
}
224+
}
225+
226+
ReactScanInternals.fiberMap.set(fiber, {
227+
count,
228+
time,
229+
lastUpdated: now,
230+
});
228231
});
229232
},
230233
onCommitFinish() {

0 commit comments

Comments
 (0)