-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Better Loaf implementation that works
- Loading branch information
1 parent
814e41c
commit e79bcc1
Showing
1 changed file
with
33 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
(function() { | ||
// See https://developer.chrome.com/docs/web-platform/long-animation-frames | ||
if (PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')) { | ||
|
||
(function () { | ||
// See https://developer.chrome.com/docs/web-platform/long-animation-frames | ||
if ( | ||
PerformanceObserver.supportedEntryTypes.includes('long-animation-frame') | ||
) { | ||
const MAX_LOAFS_TO_CONSIDER = 10; | ||
const relevantLoadEntries = []; | ||
const observer = new PerformanceObserver(list => { | ||
let longestBlockingLoAFs = [].concat(list.getEntries()).sort( | ||
(a, b) => b.blockingDuration - a.blockingDuration | ||
).slice(0, MAX_LOAFS_TO_CONSIDER); | ||
const observer = new PerformanceObserver(list => {}); | ||
observer.observe({type: 'long-animation-frame', buffered: true}); | ||
const entries = observer.takeRecords(); | ||
|
||
// re-package | ||
for (let entry of longestBlockingLoAFs) { | ||
const info = {}; | ||
info.blockingDuration = entry.blockingDuration; | ||
info.duration = entry.duration; | ||
info.styleAndLayoutStart = entry.styleAndLayoutStart; | ||
info.renderStart = entry.renderStart; | ||
info.scripts = []; | ||
for (let script of entry.scripts) { | ||
const s = {}; | ||
s.forcedStyleAndLayoutDuration = script.forcedStyleAndLayoutDuration; | ||
s.invoker = script.invoker; | ||
s.invokerType = script.invokerType; | ||
s.sourceFunctionName = script.sourceFunctionName; | ||
s.sourceURL = script.sourceURL; | ||
info.scripts.push(s); | ||
} | ||
relevantLoadEntries.push(info); | ||
} | ||
return relevantLoadEntries; | ||
}); | ||
observer.observe({ type: 'long-animation-frame', buffered: true }); | ||
let longestBlockingLoAFs = [] | ||
.concat(entries) | ||
.sort((a, b) => b.blockingDuration - a.blockingDuration) | ||
.slice(0, MAX_LOAFS_TO_CONSIDER); | ||
|
||
// re-package | ||
for (let entry of longestBlockingLoAFs) { | ||
const info = {}; | ||
info.blockingDuration = entry.blockingDuration; | ||
info.duration = entry.duration; | ||
info.styleAndLayoutStart = entry.styleAndLayoutStart; | ||
info.renderStart = entry.renderStart; | ||
info.scripts = []; | ||
for (let script of entry.scripts) { | ||
const s = {}; | ||
s.forcedStyleAndLayoutDuration = script.forcedStyleAndLayoutDuration; | ||
s.invoker = script.invoker; | ||
s.invokerType = script.invokerType; | ||
s.sourceFunctionName = script.sourceFunctionName; | ||
s.sourceURL = script.sourceURL; | ||
info.scripts.push(s); | ||
} | ||
relevantLoadEntries.push(info); | ||
} | ||
return relevantLoadEntries; | ||
} | ||
})(); | ||
|