What do the “Not optimized” warnings in the Chrome Profiler mean?

前端 未结 5 1513
失恋的感觉
失恋的感觉 2021-01-30 16:20

When I use the Developer Tools in Chrome to collect JavaScript CPU Profiles, I am getting two mysterious warnings on functions:

  • Not optimized: optimized too many t
相关标签:
5条回答
  • 2021-01-30 16:27

    I had a

    function generate_year_blob(year,action,callback){ ... do_blob({act: action, cb:callback, ...}) ... }

    and I called it always using only one parameter like this generate_year_blob(this_year).

    Those action (expected to be string) and callback (expected to be function) were passed to do_blob() function.

    When I changed the the call from generate_year_blob(this_year) to generate_year_blob(this_year,'',null), the 'Not optimized: optimized too many times' warning disappeared.

    I didn't find this out immediately, because there were many similar functions generate_month_blob(...), generate_day_blob(...) etc. which were called with all parameters defined.

    0 讨论(0)
  • 2021-01-30 16:29

    The first one is likely because the engine has optimised it, but then found the optimisation no good for some reason (maybe the return type varies over time, etc).

    Enabling the flags --trace-opt and --trace-deopt should help you pinpoint.

    My excuses if the links provided in the comments already pointed you there.

    0 讨论(0)
  • 2021-01-30 16:37
    1. I believe that "Not optimized: optimized too many times" refers to when the chrome optimizer keeps reoptimizing a function.

      https://groups.google.com/forum/#!topic/v8-users/_oZ4fUSitRY

      If I recall correctly, there are several things that can cause this including parameters that change type, I'll try to dig up the link.

      This one is somewhat cryptic and fixes will depend on your code. I've had this pop up in my code many times and sometimes I just can't fix it.

    2. 'Not optimized: inlining bailed out' Seems answered in the link you posted.

    3. For the try/catch, a non-exhaustive but useful list of Chrome optimization quirks can be found on this github page:

      https://github.com/petkaantonov/bluebird/wiki/Optimization-killers

      This page mentions that try/catches are not currently optimized:

      • Generator functions
      • Functions that contain a for-of statement
      • Functions that contain a try-catch statement
      • Functions that contain a try-finally statement
      • Functions that contain a compound let assignment
      • Functions that contain a compound const assignment
      • Functions that contain object literals that contain proto, or get or set declarations.
    0 讨论(0)
  • 2021-01-30 16:48

    I was getting a lot of the 'Not optimized: optimized too many times' warnings and these functions were running much slower than they should have.

    I was able to fix these functions by doing these things:

    1. Removing unused variable declarations

    2. Removing function calls from loops that iterate many times (>1000 i suspect)

    0 讨论(0)
  • 2021-01-30 16:49

    The explanations for these bailout reasons are being crowdsourced and documented in this github thread: https://github.com/GoogleChrome/devtools-docs/issues/53

    The short explanation: V8 will not try to optimize functions with some constructs, try/catch block is one example, the full list may change over time as the engine evolves. It can also give up if it tries to optimize and then has to deoptimize some hot function too many times (e.g. because of the type feedback being different each time the function executes).

    0 讨论(0)
提交回复
热议问题