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.

avoid deoptimizations in v8

See original GitHub issue

There are several code parts that trigger alot of deoptimizations in v8. Run chrome --js-flags="--trace-opt --trace-deopt --trace" to get the trace info. For my typical benchmark with ls -lR /usr/lib the demo shows the following:

[deoptimizing (DEOPT eager): begin 0x27f83bd2d3b9 <JSFunction TextRenderLayer._forEachCell (sfi = 0x27f83bd1bf49)> (opt #2) @3, FP to SP delta: 96, caller sp: 0x7ffc6b031a28]
            ;;; deoptimize at <http://localhost:3000/dist/bundle.js:7140:36>, wrong map

[deoptimizing (DEOPT soft): begin 0x27f83bd2bea9 <JSFunction StaticCharAtlas.draw (sfi = 0x27f83bd2b189)> (opt #1) @19, FP to SP delta: 56, caller sp: 0x7ffc6b031748]
            ;;; deoptimize at <http://localhost:3000/dist/bundle.js:7740:36>, Insufficient type feedback for generic named access

[deoptimizing (DEOPT soft): begin 0x27f83bd19341 <JSFunction InputHandler.print (sfi = 0x27f83bd04fd1)> (opt #16) @53, FP to SP delta: 144, caller sp: 0x7ffc6b031dd0]
            ;;; deoptimize at <http://localhost:3000/dist/bundle.js:1999:30>, Insufficient type feedback for generic named access

[deoptimizing (DEOPT eager): begin 0x27f83bd19341 <JSFunction InputHandler.print (sfi = 0x27f83bd04fd1)> (opt #19) @21, FP to SP delta: 144, caller sp: 0x7ffc6b031e90]
            ;;; deoptimize at <http://localhost:3000/dist/bundle.js:2027:35>, wrong map

[deoptimizing (DEOPT lazy): begin 0x27f83bd4b819 <JSFunction Terminal.blankLine (sfi = 0x31d068a7c271)> (opt #28) @18, FP to SP delta: 72, caller sp: 0x7ffc6b031d00]

[deoptimizing (DEOPT eager): begin 0x27f83bd2d3b9 <JSFunction TextRenderLayer._forEachCell (sfi = 0x27f83bd1bf49)> (opt #7) @27, FP to SP delta: 96, caller sp: 0x7ffc6b031a28]
            ;;; deoptimize at <http://localhost:3000/dist/bundle.js:7143:36>, wrong map

[deoptimizing (DEOPT eager): begin 0x27f83bd17d11 <JSFunction EscapeSequenceParser.parse (sfi = 0x27f83bd11d89)> (opt #20) @21, FP to SP delta: 152, caller sp: 0x7ffc6b031fa8]
            ;;; deoptimize at <http://localhost:3000/dist/bundle.js:1561:25>, wrong call target

[deoptimizing (DEOPT soft): begin 0x27f83bd2c9a1 <JSFunction BaseRenderLayer.drawChar (sfi = 0x27f83bd1e431)> (opt #6) @39, FP to SP delta: 128, caller sp: 0x7ffc6b0318b0]
            ;;; deoptimize at <http://localhost:3000/dist/bundle.js:6278:18>, Insufficient type feedback for generic named access

[deoptimizing (DEOPT soft): begin 0x27f83bd19c81 <JSFunction InputHandler.charAttributes (sfi = 0x27f83bd066f1)> (opt #45) @9, FP to SP delta: 72, caller sp: 0x7ffc6b031eb8]
            ;;; deoptimize at <http://localhost:3000/dist/bundle.js:2619:34>, Insufficient type feedback for generic named access

[deoptimizing (DEOPT eager): begin 0x27f83bd2d3b9 <JSFunction TextRenderLayer._forEachCell (sfi = 0x27f83bd1bf49)> (opt #2) @3, FP to SP delta: 96, caller sp: 0x7ffc6b031a28]
            ;;; deoptimize at <http://localhost:3000/dist/bundle.js:7140:36>, wrong map

Not all of those are fixable, since the optimizer might end up with a wrong assumption. Still some of them can be fixed by avoiding some anti pattern:

There was another deopt in EscapeSequenceParser.parse https://github.com/xtermjs/xterm.js/blob/5620da49d8590efd79ca06e995c89866c239e53e/src/EscapeSequenceParser.ts#L378 which I lost the trace data for, this is an out of bound error (right overflow for charCodeAt), which happens only now and then (I guess it depends on the input data provided). When it happens parse kinda doubles the runtime from ~120 ms to ~250 ms. Should be easy to fix.

Details

  • Browser and browser version: chrome v65 & electron v58
  • OS version: linux
  • xterm.js version: master

Steps to reproduce

  1. Run chrome --js-flags="--trace-opt --trace-deopt --trace" with the demo
  2. dig through the trace output

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jerchcommented, Jul 6, 2018

Oh well didnt know that ‘y’ feature, thought the line click is always commit aware. Gonna change the links.

0reactions
Tyriarcommented, Oct 7, 2019

I think @jerch has covered most of these and we’re always wary when new things come in. Reopen if it needs more

Read more comments on GitHub >

github_iconTop Results From Across the Web

How JavaScript works: Optimizing the V8 compiler for efficiency
A guide to compiler-friendly Javascript optimization methods to help front-end devs write more efficient Javascript and reduce slowdowns.
Read more >
Performance tips for JavaScript in V8 - web.dev
This will help you avoid premature optimization. The best basic advice for getting good performance in Web applications is:.
Read more >
The V8 Engine and JavaScript Optimization Tips - DigitalOcean
A 5000 feet overview of how the V8 JavaScript engine works and how to write JavaScript code that's optimized for fast parsing speed....
Read more >
An Introduction to Speculative Optimization in V8 - Ponyfoo
An impressively low-level article that we hope gives you a good idea about what happens in V8 when it comes to optimization.
Read more >
How to Disable V8's Optimizing Compiler - Stack Overflow
I'm writing a constant-time string comparison function (for node.js) and would like to disable V8's optimizing compiler for this single ...
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