$30 off During Our Annual Pro Sale. View Details »

๐Ÿ‡ณ๐Ÿ‡ฑ Frontmania 2024 (Lightning)

๐Ÿ‡ณ๐Ÿ‡ฑ Frontmania 2024ย (Lightning)

Speed at Scale: Optimizing The Largest CX Platform Out There

In a world with a wide variety of network connections, any user can have a slow experience, and apps that delight users on fast connections can barely be usable on slow ones.

In this session, I'll share my journey of gradually adapting how we deliver pages to better cater to our user's constraints on a platform with 15mi+ sessions per monthโ€”where simply rewriting everything from scratch is not an option.

With an eye on maintenance and scalability, we'll discuss legacy codebases, automation/code generation, polyfilling strategies, main thread offloading, and many other tips and tricks for large platforms targeting emerging markets.

Matheus Albuquerque

October 10, 2024
Tweet

More Decks by Matheus Albuquerque

Other Decks in Programming

Transcript

  1. Hallo, Utrecht! ๐Ÿ‘‹ ๐Ÿ‡ณ๐Ÿ‡ฑ SPEED AT SCALE: OPTIMIZING THE LARGEST

    CX PLATFORM OUT THERE โ€ข OCTOBER 10, 2024. lightning
  2. Matheus Albuquerque โ† ๐Ÿ‘จ๐Ÿ’ป Staff SWE @ Medallia โ† โšก

    Google Developer Expert โ† ๐• ythecombinator
  3. [โ€ฆ] โ€œWhile browsing HackerNews, I sometimes get the feeling that

    every developer out there is working for FAANG, as there are always posts from those people doing some hyped stuff.โ€ [โ€ฆ] โ€”โ€‰The silent majority, by Vadim Kravcenko
  4. [โ€ฆ] โ€œBut letโ€™s be straight, thatโ€™s like 1% of all

    of the developers out there โ€” the rest of them are just lurking and coding with their language of choice and being content with it. Be it Fortran, COBOL, Perl, or PHP.โ€ [โ€ฆ] โ€”โ€‰The silent majority, by Vadim Kravcenko
  5. This talk is not aboutโ€ฆ โ† React 19, Svelte 5,

    Vue 3โ€ฆ โ† ISG, SSR, Streaming SSRโ€ฆ โ† Progressive/Selective/Partial Hydrationโ€ฆ โ† Islands Architecture, Resumabilityโ€ฆ
  6. #definition ๐Ÿง Jscodeshift is a tool that runs a transformation

    script over one or more JavaScript or TypeScript files.
  7. WE HAD TO SUPPORT, IN PARALLEL: โ† DIFFERENT VERSIONS OF

    DEVELOPER DEPENDENCIES (E.G. node.js, Webpack, Babel, ETC.) โ† DIFFERENT VERSIONS OF APPLICATION DEPENDENCIES (E.G. React ITSELF) โ† DIFFERENT STRATEGIES USED FOR BUNDLING AND SERVING CODEGEN: REQUIREMENTS
  8. CODEGEN: AFTER REPO / PACKAGES / (LEGACY) A (LEGACY) B

    NEXT GENERATION (CONFIG + SCRIPTS)* NEXT GENERATION (CODE GENERATED) โ€ฆ
  9. CODEGEN: AFTER REPO / PACKAGES / (LEGACY) A (LEGACY) B

    NEXT (CONFIG + SCRIPTS)* NEXT (CODE GENERATED) โ€ฆ โ† DEFAULT BUNDLE THATโ€™S SERVED. โ† ACTIVE DEVELOPMENT (IE. NEW FEATURES/FIXES) HAPPENS HERE. โ† THIS IS THE CODE THATโ€™S PUSHED TO THE REPO. โ† LEGACY DEPENDENCIES: REACT 15, WEBPACK 1, NODE 10, ETC.
  10. CODEGEN: AFTER REPO / PACKAGES / (LEGACY) A (LEGACY) B

    NEXT (CONFIG + SCRIPTS)* NEXT (CODE GENERATED) โ€ฆ โ† HIDDEN BEHIND A FEATURE FLAG. โ† MODERN DEPENDENCIES: REACT 16, WEBPACK 5, NODE 18, ETC. โ† MOSTLY COMPOSED OF CODE TRANSFORMERS, AUTOMATION SCRIPTS, AND WEBPACK/BABEL CONFIG. โ† ALSO, PARTS OF THE CODE THAT CAN'T BE CODE GENERATED (IE. UNIT AND FUNCTIONAL TESTS).
  11. CODEGEN: AFTER REPO / PACKAGES / (LEGACY) A (LEGACY) B

    NEXT (CONFIG + SCRIPTS)* NEXT (CODE GENERATED) โ€ฆ โ† GENERATED AT BUILD TIME (IE. CI/LOCALLY). โ† REACT COMPONENTS, UTILS, AND OTHER BUSINESS LOGIC. โ† THIS CODE IS NEVER PUSHED (1K+ LINES IN GITIGNORE FILE).
  12. export default function transformer(file: FileInfo, api: API) { const j

    = api.jscodeshift; const root = j(file.source); const variableDeclarators = root.findVariableDeclarators('foo'); variableDeclarators.renameTo('bar'); return root.toSource(); } CODEGEN: BASIC TRANSFORMER
  13. CODEGEN: TRANSFORMER GROUPS const transformGroups = [ { label: "PropTypes

    โ†’ prop-types", pattern: "./src/ * /.{js,jsx}", transformerPath: proptypes, }, { label: "legacy-testing/src/testUtils โ†’ ./utils/test", pattern: "./src/ * /.jsx", transformerPath: testUtils, }, { label: " * .scss โ†’ * .global.scss", pattern: "./src/ * /.jsx", transformerPath: cssGlobals, }, ];
  14. #protip ๐Ÿ’ก Dynamic imports are a great tool but, like

    all optimizations, they donโ€™t come for free.
  15. WHICH BROWSERS ARE VISITING OUR APP? SPEED AT SCALE: OPTIMIZING

    THE LARGEST CX PLATFORM OUT THERE / TARGETING DIFFERENT BROWSERS
  16. SUMMING UPโ€ฆ <script> var script = document.createElement('script'); var prefix =

    (!('noModule' in check)) ? "/ie11" : "/esm"; script.src = prefix + "/index.js"; document.head.appendChild(script); </script>
  17. BUNDLE FOOTPRINT หœ37% SMALLER BUNDLE FOOTPRINT ON MODERN BROWSERS: 279.15

    KB โ†’ 176.78 KB MODERN หœ25% SMALLER BUNDLE FOOTPRINT ON LEGACY BROWSERS 279.15 KB โ†’ 223.1 KB LEGACY
  18. BUNDLE FOOTPRINT BROWSERS THAT SUPPORT ES MODULES AND HAPPEN NOT

    TO NEED EXTRA POLYFILLS. AS OF SEPTEMBER 21, 2024, THESE REPRESENT 95.93% OF THE GLOBAL USAGE. MODERN BROWSERS THAT DONโ€™T FIT THE PREVIOUS CRITERIA. MOSTLY THOSE ARE PRE-2018 BROWSERS WITH INTERNET EXPLORER BEING THE HIGHLIGHT. LEGACY
  19. โ† FCP: 6S FASTER โ† SPEED INDEX: 3.5S FASTER โ†

    LCP: 2.4S FASTER โ† TTI: 2S FASTER CORE WEB VITALS โฌ‡
  20. TIMINGS VISUALLY COMPLETE LAST VISUAL CHANGE LOAD TIME (ONLOAD) LOAD

    TIME (FULLY LOADED) DOM CONTENT LOADED FEATURE FLAG ON FEATURE FLAG OFF โ€” WEBPAGETEST
  21. #1 of 3 SPEED AT SCALE: OPTIMIZING THE LARGEST CX

    PLATFORM OUT THERE / CLOSING THOUGHTS UNDERSTANDING INTERNALS HELPS US IMPLEMENT OUR OWN ABSTRACTIONS. E.G. THE jscodeshift-BASED ARCHITECTURE UPGRADE TOOL.
  22. #2 of 3 YOU HAVE TO SHIP POLYFILLS TO ALL

    BROWSERS YOUR USERS MIGHT USEโ€ฆ . . . BUT IT'S A BAD IDEA TO SHIP ALL THEORETICALLY REQUIRED POLYFILLS TO ALL OF THEM! SPEED AT SCALE: OPTIMIZING THE LARGEST CX PLATFORM OUT THERE / CLOSING THOUGHTS
  23. #3 of 3 THERE'S NO SILVER BULLET. IDENTIFY YOUR CORE

    METRICS. SPEED AT SCALE: OPTIMIZING THE LARGEST CX PLATFORM OUT THERE / CLOSING THOUGHTS