Back to JetBrains

Integrating a Web-Based Profiler Into IntelliJ IDEA

JetBrainsNovember 17, 202634m
In a Nutshell

Johannes built an IntelliJ plugin that converts JFR files to Firefox Profiler format and serves the web-based profiler UI inside the IDE, giving users right-click profiling with flame graphs, tree views, and source navigation. The plugin has 37k downloads and demonstrates a hybrid architecture where a Kotlin server wraps the Firefox Profiler web UI and communicates with the IDE via HTTP/WebSocket. This approach trades native Swing complexity for easier web development while accepting trade-offs like larger plugin size, JCEF bugs, and dual-stack maintenance.

AI-Generated Notes

These notes were generated by AI and may contain inaccuracies.

Johannes Bechberger works at SAP on SapMachine, one of the OpenJDK distributions. Several years ago, he attempted to make debugging faster, which led him to profiling challenges. He had tests that were slow and wanted to understand why, but only had access to IntelliJ Community Edition. His desired workflow was simple: right-click to profile with JFR (JDK Flight Recorder) or async-profiler, both modern Java profilers. However, these options weren't directly available in the IDE.

A poll was conducted asking who has used a profiler before. The speaker notes that when asking this question at conferences, most people haven't heard of profilers, which he finds unfortunate.

Profilers are beneficial when programs are slow and you need to identify the culprit. Using profilers involves detective work to understand performance issues.

This talk builds on previous presentations given at the Firefox profiler and at the Firefox dev room at FOSDEM in 2023 or 2024, where the speaker discussed integrating a web-based profiler into IntelliJ.

When researching profiling options for himself, the speaker identified two main open source tools. One was a larger Eclipse-based application. The other involved flame graphs, which he describes as valuable because, quoting Mario Fusco: "I love flame graphs when you do something stupid, it punches you in your face. It's impossible not to see it."

Flame graphs work by combining stack traces so the lowest bar shows full width, indicating the main method runs all the time. When the main method calls method A 50% of the time, this branches visually. Users can see which parts of the program took how much time. While simple and generated by many tools by default, flame graphs lack deeper digging capabilities.

The other open source tool is JDK Mission Control, an Eclipse-based tool that's been available for a long time. It allows deep data analysis but is not easy to use. When discussing this tool with people, they often say "It's the best we have," which the speaker identifies as a problem.

The speaker wanted a tool in the middle: well-integrated into his IDE with more features than just flame graphs, but not as complicated as existing tools. He decided to write his own profiler. His boss approved the project, especially noting it was August during vacation season when there wasn't much activity. Other colleagues internally also found it interesting.

Initially considering writing everything himself, the speaker realized he wasn't the strongest UI developer and lacked UI technology knowledge. He explored visualization options including speedscope (a slightly better flame graph), a flame graph plugin for IntelliJ, and IntelliJ's built-in profiler (unavailable in open source/Community Edition).

He discovered Firefox Profiler, the profiler used in Firefox for web profiling. This tool is mature with a dedicated team of two to three people, containing many desired features. Rather than developing from scratch, he considered integrating Firefox Profiler into an IDE with additional needed features.

The integration wasn't as simple as initially thought. The speaker contributed to the Firefox Profiler project for half a year to add necessary features. He learned React through making pull requests and having them rejected, then iterating on the feedback.

When used as intended for web application development, Firefox Profiler can show screenshots in the timeline and display code below. It offers many advantages beyond basic profiling.

The integration process involves taking a JFR file and converting it to the Firefox profile format using a Kotlin script. This is packaged with a server to serve the web-based UI. The prebuilt Firefox Profiler UI combines with the converter, then gets packaged into an IntelliJ plugin. The plugin wraps the server, which wraps the web UI and converter.

The Firefox Profiler file format includes metadata and, for every thread, samples recorded by asking the JVM every 10 milliseconds what it's currently doing. Stack traces and frames are recorded, with frames linked to functions. The format is optimized for compactness but difficult to emit. The speaker spent two to three weeks on the format implementation and contributed to documentation improvements.

The complete plugin wraps a server serving Firefox Profiler with the converter, offers convenience functions, and integrates with the JVM. It's downloadable as "Java JFR Profiler" and has achieved 37,000 downloads. The speaker continues active development with regular bug fixes and feature additions.

With a simple main method running Fibonacci computation, users can right-click to profile. The plugin opens a window showing additional information like how many times methods were interpreted versus compiled. IDE integration allows viewing source code with hit counts per line directly in the IDE.

Double-clicking a method jumps back to the IDE source. The Firefox Profiler wasn't originally designed for IDE integration, but the speaker extended it by passing arguments at startup. When users double-click, parameters pass to the server, which runs in the plugin context and determines appropriate actions.

The plugin was one of the first open source profiler plugins for IntelliJ. It now includes tree view support as another visualization option.

For the remainder of the talk, a simpler plugin is demonstrated because Firefox Profiler has grown complex over time. The speaker added features like MCP support for JetBrains AI plugins. This simpler plugin allows typing class patterns to show matching classes by package or name, displaying source code with navigation between classes, events, and methods.

The class browser embeds a web browser within IntelliJ, making it difficult to distinguish from the native IDE. The implementation uses Chromium embedded via JCEF (JetBrains Chromium Embedded Framework) with standard web frameworks like Vue or React.

The plugin uses GET requests for the web frontend to interact with the IDE through the built-in server, enabling actions like retrieving classes or navigating to locations. WebSockets handle communication from IDE to web frontend. Javalin serves as the Java server framework due to its simplicity, though Spring Boot could also work.

JetBrains documentation recommends implementing UI with the default Swing framework and suggests using JCEF only when displaying HTML documents or when the standard approach isn't sufficient. The speaker found Chromium bugs during testing, noting it doesn't work as fluently but offers simpler development.

Web UIs are standard for applications since few developers use Swing for UIs. CSS layout, animations, tooling, frameworks, and large frontend library ecosystems make web development far easier than Swing development.

The approach requires two separate tech stacks, shipping a full different application, launching embedded Chromium (increasing size), and developing a full-stack application. JCEF isn't available in Android Studio. Bugs encountered include keyboard focus problems, scrolling issues, and Linux compatibility problems. It requires more testing than native approaches.

An indirection layer through HTTP connections is slower than direct method calls. The embedded Chromium version typically lags 6-12 months behind current versions, though this matters less since arbitrary JavaScript isn't executed.

The architecture separates IntelliJ IDE (Java/Kotlin) from web frontend, communicating via HTTP or WebSocket. WebSocket messages are typically JSON. The class browser connects the web frontend to IDE channels like PSI (Program Structure Interface) and PSI listeners, informing the frontend when source code changes or when users request to see specific classes.

The API allows independent testing of frontend and Java parts through mocking. A browser window launches the application. The same Firefox Profiler version runs both in the IDE and on the internet, enabling integration into other IDEs like VS Code or standalone usage without IDE integration features.

When users type in a filter box, debouncing prevents excessive IDE queries. The application sends GET requests for matching classes, the class processor asks the IDE for information, and results return as lists then JSON arrays using standard serialization libraries. This multi-step process contrasts with single-step Swing applications but offers testing advantages.

The Gradle build script requires Node installation and frontend building, with built frontend assets placed in resources. Build times increase and new dependencies are introduced.

The server implementation is straightforward, getting the IDE project and asking for reports. The backend needs to know server locations, typically on localhost at the same port. Simple routes handle theme matching between IDE and web frontend using Javalin.

Embedded Chromium presents challenges like dropped first-load promises, requiring sleep-and-check patterns. Half the code addresses rough edges, but the approach enables plugin development without Swing knowledge or deep IDE API dependencies.

The speaker is developing a heap dump analyzer for upcoming release. Contact information includes Mastodon, GitHub, sapmachine.io, and occasional blogging.

Regarding whether LLMs could help with format conversion between profiler formats, the speaker notes the plugin predates widespread LLM use. However, LLMs helped rebase pull requests for Firefox Profiler migration after two years, completing in half a day what would have been a massive manual task.

The speaker doesn't aim for broad IDE version compatibility with JCEF due to breaking API changes. He uses the simplest API (launch and load URL) and targets recent IntelliJ versions (2025, 2026), dropping old releases when workarounds become too cumbersome. He recommends using HTTP servers over JCEF for sanity preservation, citing days spent debugging JCEF issues.

When asked about profiling smooth scrolling issues in JCEF versus native Chrome, the speaker notes Firefox Profiler achieves smooth performance through hardcore optimization by its dedicated team. Similar scrolling issues exist in JCEF implementations.

Optimizing web applications is much harder than optimizing Java applications. You have to build in a Chromium profiler there.

Optimizing your web application and then just pray because yes, optimizing web applications yourself is much harder than Java applications.

This is one of the disadvantages of the approach.

Thank you to Johannes for the nice presentation.

Time available for one or two ruffle questions.

Keep JetBrains in your library

Save the videos and channels worth coming back to, and find them again in one place.