Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript profiling with per-statement results

I've got a highly recursive JavaScript function, which calls no other JavaScript functions. It's just the one function calling itself doing some simple logic and calling system functions (Array.slice, Array.splice , Array.push, etc.).

And I'm trying to optimize it, however Chrome's and Firefox's (the only browsers the website works in) DevTools and Firebug's profilers don't show anything more specific than function calls. Visual Studio has a nice thing where after profiling an application, it will tell you what percent of execution was spent on each line of your functions, which is really helpful.

I've tried breaking up the function into smaller functions, but then the function call overhead inflates to take up most of my execution time.

like image 349
zacaj Avatar asked Oct 31 '22 07:10

zacaj


2 Answers

Firebug's and the DevTools' profilers provide you with detailed information on how much time was spent within each function. See the following screenshots:

Firebug (Own Time column) Profiler output in Firebug

Firefox DevTools (Self Time column) Profiler output in Firefox DevTools

Chrome DevTools (Self column) Profiler output in Chrome DevTools

The Firefox DevTools furthermore allow you to include platform data by enabling the option Show Gecko Platform Data within the Performance panel options:

Firefox DevTools *Performance* panel option to include Gecko platform data

Though the tools only display data per-function. They do not allow you to display per-line, or to be more precise, per-statement information, probably because this is something the JavaScript author cannot influence directly.

If you believe that this information can be relevant for a JavaScript author, you should file requests for each of those tools to implement this feature explaining the reasoning behind it.

like image 185
Sebastian Zartner Avatar answered Nov 08 '22 09:11

Sebastian Zartner


Intel XDK provides information you are asking for. Here is a link to the Inbtel XDK profiling tools: https://software.intel.com/en-us/xdk/docs/using-the-profile-tab There are several pictures and help how to use it.

We are collecting the profile and annotate the source view by the self time metrics. enter image description here

Currently we are doing this on Android devices, but have plans to migrate GUI to CDT and upstream it. But even before upstreaming this functionality will be available on Windows and Linux platforms in the browser named Crosswalk. Crosswalk is a chromium based browser, containing promising features like SIMD.js or WebCL.js

Several more worlds regarding collected information. Intel XDK JavaScript CPU profiler annotates only sources by self time, but we are working on adding total times - how much time was spend for certain line and all callee functions from this line.

For running of the profiling you need to download XDK, create new project and add your code to it. Then switch to Profile tab, plug the device via wire, select CPU profiler if it is not selected and press Profile button. Waiting your feedback on using it.

like image 35
Andrey Malyshev Avatar answered Nov 08 '22 07:11

Andrey Malyshev