The Challenge
PlantUML is a powerful diagramming tool written in Java. Traditionally, this means:- Cannot run directly in web browsers
- Requires a server to render diagrams
- Adds latency and server load
- Complicates deployment and scaling
The Solution: CheerpJ
CheerpJ is a compiler that converts Java bytecode into WebAssembly and JavaScript, enabling Java applications to run natively in the browser. This revolutionary approach allows PlantUML to run client-side with no server required.CheerpJ compiles Java bytecode (from .jar files) into WebAssembly and JavaScript, making it possible to run entire Java applications in modern web browsers.
plantuml-core
Plant Together uses plantuml-core, a pure JavaScript implementation of PlantUML powered by CheerpJ. This brings several major benefits:- No server rendering - All diagram generation happens in the user’s browser
- Instant updates - No network latency for diagram rendering
- Reduced costs - No need for diagram rendering servers
- Better privacy - Diagram content never leaves the user’s browser
- Offline capable - Works without an internet connection after initial load
Implementation Details
Initialization
Before rendering diagrams, CheerpJ and PlantUML need to be initialized:The initialization happens once when the application loads. After that, PlantUML is ready to render diagrams instantly.
SVG Rendering
Plant Together uses SVG output for crisp, scalable diagrams:PNG Rendering (Alternative)
While Plant Together primarily uses SVG, PNG rendering is also supported:Error Handling
PlantUML syntax errors are captured and displayed to the user:- Identifies the line number with the error
- Highlights it in the Monaco Editor
- Displays the error message to the user
Runtime Resources
CheerpJ requires various Java runtime resources to execute PlantUML. These are preloaded for optimal performance:Credits and Inspiration
Plant Together’s implementation is heavily based on plantuml.js by @sakirtemel, with modifications to:- Work with React’s component lifecycle
- Support SVG output (original was PNG only)
- Integrate with the collaborative editing workflow
- Handle errors gracefully in the UI
Performance Characteristics
- Initial Load - Takes a few seconds to initialize CheerpJ and load PlantUML (~5-10 seconds)
- Subsequent Renders - Very fast, typically under 100ms for simple diagrams
- Complex Diagrams - May take longer, but still faster than server round-trips
- Memory Usage - Runs in a WebAssembly sandbox with controlled memory
After the initial load, PlantUML rendering is nearly instantaneous for most diagrams.
Advantages Over Server Rendering
| Aspect | Client-Side (CheerpJ) | Server-Side |
|---|---|---|
| Latency | Instant (no network) | 100-500ms network delay |
| Privacy | Content stays local | Must send to server |
| Cost | No server needed | Server resources required |
| Scalability | Infinite (client CPUs) | Limited by server capacity |
| Offline | Works offline | Requires connection |
Learn More
Related Technologies
Monaco Editor
The editor used for PlantUML code
WebSockets
Real-time sync for collaborative editing