V8 JavaScript engine
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
v8.dev →V8 has built-in sample-based profiling. Profiling is turned off by default, but can be enabled via the --prof command-line option. The sampler records stacks of both JavaScript and C/C++ code. To start profiling, use the --prof option. When profiling, V8 generates a v8.log file which contains profiling data. Make sure d8 used for analysis was not built with is component build ! Statistical profiling result from benchmarks v8.log, (4192 ticks, 0 unaccounted, 0 excluded). [Bottom up (heavy) profile]: Note: percentage shows a share of a particular caller in the total amount of its parent calls. Callers occupying less than 2.0% are not shown. Today’s highly optimized virtual machines can run web apps at blazing speed. But one shouldn’t rely only on them to achieve great performance: a carefully optimized algorithm or a less expensive function can often reach many-fold speed improvements on all browsers. Chrome DevTools ’ CPU Profiler helps you analyze your code’s bottlenecks. But sometimes, you need to go deeper and more granular: this is where V8’s internal profiler comes in handy. Let’s use that profiler to examine the Mandelbrot explorer demo that Microsoft released together with IE10. After the demo release, V8 has fixed a bug that slowed down the computation unnecessarily (hence the poor performance of Chrome in the demo’s blog post) and further optimized the engine, implementing a faster exp() approximation than what the standard system libraries provide. Following these changes, the demo ran 8× faster than previously measured in Chrome. But what if you want the code to run faster on all browsers? You should first understand what keeps your CPU busy . Run Chrome (Windows and Linux Canary ) with the following command line switches, which causes it to output profiler tick information (in the v8.log file) for the URL you specify, which in our case was a local version of the Mandelbrot demo without web workers: When preparing the test case, make sure it begins its work immediately upon load, and close Chrome when the computation is done (hit Alt+F4), so that you only have the ticks you care about in the log file. Also note that web workers aren’t yet profiled correctly with this technique. Then, process the v8.log file with the tick-processor script that ships with V8 (or the new practical web version): The top section shows that V8 is spending more time inside an OS-specific system library than in its own code. Let’s look at what’s responsible for it by examining the “bottom up” output section, where you can read indented lines as “was called by” (and lines starting with a mean that the function has been optimized by TurboFan): [Bottom up (heavy) profile]: Note: percentage shows a share of a particular caller in the total amount of its parent calls. Callers occupying less than 2.0% are not shown. More than 44% of the total time is spent executing the exp() function inside a system library ! Adding some overhead for calling system libraries, that means about two thirds of the overall time are spent evaluating Math.exp() . If you look at the JavaScript code, you’ll see that exp() is used solely to produce a smooth grayscale palette. There are countless ways to produce a smooth grayscale palette, but let’s suppose you really really like exponential gradients. Here is where algorithmic optimization comes into play. This example shows how V8’s internal profiler can help you go deeper into understanding your code bottlenecks, and that a smarter algorithm can push performance even further. To find out more about how benchmark that represent today’s complex and demanding web applications, read How V8 measures real-world performance .
Excerpt from the official site · 2,511 chars · not written by Vinony
via Wikidata · CC0
via Wikidata sitelinks · CC0
Discovered by embedding cosine similarity (sentence-transformers MiniLM, 384-dim).