question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scanner.js start-up performance could be improved

See original GitHub issue

Hello y’all! I ran some profiles of Notion’s startup performance today and noticed that Linkifyjs is very expensive to import. Specifically, the file linkifyjs/lib/linkify-core/scanner.js file appears to be quite expensive. I wonder if the tactic of using "a|b|c|...".split('|') is expensive, or if the creation of the parser states involves some kind of n^2 computation.

Anyways, I was surprised to find that Linkify was the single most expensive dependency that Notion imports, and I wanted to let you know in case you find the information useful!

Here’s a screenshot from Chrome DevTools of the boot up of the Notion web-app in a production-like environment. You can see how importing linkify compares to some other 3rd party dependencies we use like Moment and Prism.js.

image

My suggestion is that you take some time to profile the scanner, and see what work you can defer to the first run of a public method, so the library is lazy internally.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

3reactions
nfrassercommented, Feb 26, 2021

Hi @justjake, thanks for reporting this, I’ll be looking at this over the next couple of days

2reactions
nfrassercommented, Mar 8, 2021

Good news, managed a combination of all of the above to get the initial load time down from ~30ms to ~1ms. Managed this with both revamped internals + delayed initialization. The means there’s an extra penalty you now pay the first time you run linkify (only about ~4ms thanks to the revamped internals), but future runs are faster than ever.

The fix is now available in v3.0.0-beta.1. A production release will be out in the coming weeks.

v2 vs v3 performance comparison

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Start-up Performance. Update - Medium
This is based on the idea that most pages have JS functions that are lazily executed if at all. Pre-parsing can speed up...
Read more >
Don't fight the browser preload scanner - web.dev
Find out what the browser preload scanner is, how it helps performance, and how you can stay out of its way.
Read more >
Issues - GitHub
The demo is faster at scanning and can scan code that my setup can't. ... https://zxing-js.github.io/ngx-scanner/ Demo Performance is better ...
Read more >
Dive into React Native performance - Engineering at Meta
Optimizing performance is a big part of this. Here is the story of how we made React Native app startup twice as fast....
Read more >
The cost of JavaScript in 2019 · V8
Raw JavaScript parsing speed in V8 has increased 2× since Chrome 60. ... We can also visualize the CPU time impact of these...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found