Repository navigation
Profiling JavaScript
The JavaScript Profiler profiles Haxe/JavaScript code running in a Chromium-family browser. It starts its own
browser instance and drives the browser's V8 sampling profiler over the
Chrome DevTools Protocol. Source maps lead the results back to
your .hx files. For what all profilers share, see Profiling Overview.
Note
Experimental. IntelliJ IDEA Ultimate. See Profiling Overview.
- IntelliJ IDEA Ultimate.
- A Haxe Web Browser run configuration. For a build with
-js <file>.jsoutput, Build & run in the Haxe tool window creates one that serves the output folder. - A Chromium-family browser selected in the configuration's Browser: field: a browser of the Chrome family under Settings | Tools | Web Browsers and Preview, such as Chrome or Chromium, with the full path of its executable. See Register the browser. Firefox cannot be profiled. When the selected browser does not fit, Profile with 'JavaScript Profiler' in the Haxe tool window opens the configuration editor, titled Profiling Needs a Chromium Browser.
Programs that run in Node.js cannot be profiled.
- In the Haxe tool window, expand the build file's Actions group.
- Right-click Build & run and choose Profile with 'JavaScript Profiler'.
- Use the page in the browser window that opens.
- Stop the run from the IDE. The profiler collects the last segment, then closes the browser. If you close the browser window yourself instead, the profile keeps everything up to the last completed second.
-
In the build: adds
-D js-source-map -D source-mapthrough the Run Haxe action before-launch step, so the compiler writes a source map even without-debug.js-source-mapis the older, deprecated name ofsource-map. If your configuration builds without that step, add-D source-mapyourself. - At launch: serves the content as a normal run does, then starts a new instance of the selected browser with a temporary profile and its debugging port open. The temporary profile has none of your extensions, bookmarks or logins.
- While the page runs: collects the profile in one-second segments and appends them to the profile file, so the tab in the Profiler tool window fills in live. Besides the samples, it records the frames the browser draws and the size of the JavaScript heap.
The entry lives under Settings | Build, Execution, Deployment | Profilers | Haxe Profiler.
| Option | Meaning |
|---|---|
| Sampling interval (µs): | Time between two samples, in microseconds. The default, 1000, is V8's own default. Values below 100 or above 1000000 are raised or lowered to that limit. |
The profile is saved as captures/<date>-<time>/jsprofile.hxtsession in the configuration's content directory, or in
the project directory when the configuration opens a URL without a content directory.
The tab shows the standard Flame Graph, Call Tree and Method List views with CPU Time and Samples,
plus the Haxe Profiler tab. The plugin turns the generated JavaScript names back into Haxe names, so
pack_Main.update reads as pack.Main.update. Positions map to the .hx sources when the compiled script's source map
(<name>.js.map) sits next to it in the served directory; otherwise they point at the generated JavaScript. V8
reports one position per function, so the editor hints show times per function.
| Lane | Data | Empty when |
|---|---|---|
| Call chart | Sampled call stacks of the page's main thread. Time the engine spends idle shows as [idle], garbage collection as [gc]. |
- |
| Frames | One span per frame the browser drew. | The browser did not report its frames. The samples are still recorded. |
| GC | The time V8 spent collecting garbage, per frame (per one-second segment where no frames were reported). The span's position is only accurate to that frame or segment. | No collection happened. |
| Memory | Heap used and Heap reserved: the used and total size of the JavaScript heap, read once per second. | The browser did not report its heap size. |
| CPU load | Thread activity: how busy the page's main thread was over time, estimated from the samples. | - |
| Events, GPU memory, GPU load | Not recorded by this profiler. | Always. |
The Profiler tool window also opens V8 .cpuprofile files, for example a CPU profile saved from Chrome DevTools or
another tool. They open with the same views; their positions point at the generated JavaScript.
- Only Chromium-family browsers; not Firefox and not Node.js.
- Only the page's main thread is profiled; web workers are not.
- The memory figure covers the JavaScript heap only.
- The profiler starts with the browser; it cannot attach to a browser that is already running.
| Symptom | Cause and fix |
|---|---|
| The JavaScript Profiler entry is unavailable in the run widget | The configuration's Browser: is not a Chromium-family browser, the configuration has neither a content directory to serve nor a URL, or the IDE is still indexing. |
| No profiling data arrived - the profiler could not attach to the browser before the run ended. | The run stopped or the browser closed before the profiler connected to the page. The profiler waits up to 30 seconds for the browser to open its page. |
The results show .js positions instead of .hx files |
The source map is missing or not next to the script. Profile through Build & run, or build with -D source-map. |
Getting started
Working with projects
- The Haxe Tool Window
- Build Files
- Targets and Sections
- Resolve Context
- Libraries and Haxelib
- Defines and Custom Targets
- Building and Running
- Run Configurations
- Tools
- Compilation Server
Debugging
Testing
Profiling
Editing code
- Code Completion
- Diagnostics and Inspections
- Refactoring and Navigation
- Formatting and Code Style
- Conditional Compilation
- Editor Extras
Reference