Skip to content

Profiling JavaScript

m0rkeulv edited this page Oct 20, 2026 · 2 revisions

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.

Requirements

  • IntelliJ IDEA Ultimate.
  • A Haxe Web Browser run configuration. For a build with -js <file>.js output, 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.

Profile a page

  1. In the Haxe tool window, expand the build file's Actions group.
  2. Right-click Build & run and choose Profile with 'JavaScript Profiler'.
  3. Use the page in the browser window that opens.
  4. 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.

What the plugin does

  • In the build: adds -D js-source-map -D source-map through the Run Haxe action before-launch step, so the compiler writes a source map even without -debug. js-source-map is the older, deprecated name of source-map. If your configuration builds without that step, add -D source-map yourself.
  • 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.

Settings

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.

Results

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.

Open profiles from Chrome DevTools

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.

Limitations

  • 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.

Troubleshooting

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.

Clone this wiki locally