Bluesky app fork with some witchin' additions 💫

Instrument module init in DEV (#1787)

authored by danabra.mov and committed by

GitHub 85c26fb5 adb5ce29

+63
+50
patches/metro-runtime+0.76.8.patch
··· 1 + diff --git a/node_modules/metro-runtime/src/polyfills/require.js b/node_modules/metro-runtime/src/polyfills/require.js 2 + index ce67cb4..eeeae84 100644 3 + --- a/node_modules/metro-runtime/src/polyfills/require.js 4 + +++ b/node_modules/metro-runtime/src/polyfills/require.js 5 + @@ -22,6 +22,13 @@ global.__c = clear; 6 + global.__registerSegment = registerSegment; 7 + var modules = clear(); 8 + 9 + +if (__DEV__) { 10 + + // Added by Dan for module init logging. 11 + + global.__INIT_LOGS__ = [] 12 + + var initModuleCounter = 0 13 + + var initModuleStack = [] 14 + +} 15 + + 16 + // Don't use a Symbol here, it would pull in an extra polyfill with all sorts of 17 + // additional stuff (e.g. Array.from). 18 + const EMPTY = {}; 19 + @@ -303,7 +310,30 @@ function loadModuleImplementation(moduleId, module) { 20 + throw module.error; 21 + } 22 + if (__DEV__) { 23 + - var Systrace = requireSystrace(); 24 + + // Added by Dan for module init logging. 25 + + var Systrace = { 26 + + beginEvent(label) { 27 + + let fullLabel = initModuleCounter++ + ' ' + label 28 + + global.__INIT_LOGS__.push( 29 + + ' '.repeat(initModuleStack.length) + 30 + + ' ENTER ' + fullLabel 31 + + ) 32 + + initModuleStack.push({ 33 + + fullLabel, 34 + + startTime: nativePerformanceNow(), 35 + + }) 36 + + }, 37 + + endEvent() { 38 + + const res = initModuleStack.pop() 39 + + const fullLabel = res.fullLabel 40 + + const startTime = res.startTime 41 + + const timeElapsed = Math.round(nativePerformanceNow() - startTime) 42 + + global.__INIT_LOGS__.push( 43 + + ' '.repeat(initModuleStack.length) + 44 + + ' LEAVE ' + fullLabel + ' [' + timeElapsed + 'ms]', 45 + + ) 46 + + } 47 + + }; 48 + var Refresh = requireRefresh(); 49 + } 50 +
+13
src/Navigation.tsx
··· 472 472 performance.now() - global.__BUNDLE_START_TIME__, 473 473 ) 474 474 console.log(`Time to first paint: ${initMs} ms`) 475 + logModuleInitTrace() 475 476 476 477 // Register the navigation container with the Sentry instrumentation (only works on native) 477 478 if (isNative) { ··· 585 586 backgroundColor: colors.white, 586 587 }, 587 588 }) 589 + 590 + function logModuleInitTrace() { 591 + if (__DEV__) { 592 + // This log is noisy, so keep false committed 593 + const shouldLog = false 594 + // Relies on our patch to polyfill.js in metro-runtime 595 + const initLogs = (global as any).__INIT_LOGS__ 596 + if (shouldLog && Array.isArray(initLogs)) { 597 + console.log(initLogs.join('\n')) 598 + } 599 + } 600 + } 588 601 589 602 export { 590 603 navigate,