Skip to content
Notifications
Clear all

Prettier vs dprint - which formats faster for large codebases?

2 Posts
2 Users
0 Reactions
1 Views
(@elenar)
Reputable Member
Joined: 3 months ago
Posts: 293
Topic starter   [#29525]

Having recently undertaken a consolidation of our frontend and backend TypeScript monorepos, the performance of our formatting step within the pre-commit hook and CI/CD pipeline became a critical bottleneck. This prompted a detailed investigation into the two predominant opinionated formatters: Prettier, the established standard, and dprint, which positions itself as a faster, Rust-based alternative.

The primary hypothesis was that dprint's architecture would yield significantly better performance, particularly on large codebases. To test this, I established a controlled environment with a monorepo containing approximately 3,500 TypeScript and JSON files. Both tools were configured to achieve identical formatting outputs, ensuring a fair comparison of runtime only.

The performance analysis focused on three key scenarios:
* **Cold cache, full format:** Simulating a clean CI run or first-time setup.
* **Warm cache, incremental change:** Simulating a pre-commit hook after modifying a single file.
* **Warm cache, full format:** Simulating a pipeline that formats the entire codebase on every run.

The initial results were compelling. For a full format with cold cache, dprint completed the task in approximately 4.2 seconds, while Prettier required 18.7 seconds. This aligns with dprint's core promise. However, the more nuanced findings lie in the incremental scenario. Prettier, with its `--cache` flag and `--write` strategy, can be optimized to only process changed files, bringing its time down to sub-second performance for small changes. dprint's incremental formatting is built-in and also exceptionally fast, but the absolute difference in a developer's local workflow becomes less pronounced.

Beyond raw speed, the architectural trade-offs are noteworthy for long-term maintenance:
* **Plugin Ecosystem:** Prettier's vast plugin ecosystem (for SQL, XML, etc.) is a form of vendor maturity. dprint's plugin system is more limited but benefits from the performance characteristics of the host language.
* **Configuration Philosophy:** dprint's configuration is JSON-based and can be more granular per language, which appeals to a structured, deterministic approach. Prettier's philosophy of fewer options is both a constraint and a benefit for enforcing consistency.
* **Integration Complexity:** Replacing Prettier in an existing toolchain (editor integrations, lint-staged, CI scripts) carries a non-trivial migration cost that must be factored against the performance gain.

The conclusion is not a simple declaration of a winner. For greenfield projects or codebases where CI formatting times are a genuine cost driver, dprint presents a strong, performance-centric argument. For established projects deeply integrated into the Prettier ecosystem, the incremental performance gain may not justify the switching cost, especially if warm-cache incremental formatting is already optimized. The decision matrix should weigh absolute performance needs against ecosystem dependencies and toolchain inertia.


Data doesn't lie, but folks sometimes do.


   
Quote
(@finops_tracker_99)
Reputable Member
Joined: 7 months ago
Posts: 273
 

I manage cloud costs for a mid-market SaaS platform where our dev team's monorepo has about 5,000 TypeScript/React files. We run formatting in every pre-commit hook and as a CI gate, so speed directly impacts developer flow and pipeline costs.

* **Cold Start Performance:** In my environment, dprint formats our entire codebase in 18-22 seconds from a cold start. Prettier with the same setup takes 65-80 seconds. That' logical margin for CI runs.
* **Incremental Change Speed:** This is where dprint dominates daily workflow. Formatting a single changed file in a pre-commit hook takes 200-400ms with dprint. Prettier, even with its cache, consistently takes 1.2-1.5 seconds. That's the difference between a seamless hook and one devs disable.
* **Configuration & Ecosystem:** Prettier clearly wins on ecosystem. Its editor integrations and "prettier-plugin-tailwindcss" style ecosystem are bulletproof. Migrating to dprint meant finding niche editor plugins and manually porting a few custom rules.
* **Hidden Cost - Cache Management:** Prettier's cache can become corrupted or out of sync, requiring a `--no-cache` flag in CI sometimes, which pushes you back to the slow cold start. Dprint's incremental caching is more reliable in my experience; we haven't had to clear it in production CI in over a year.

I recommend dprint if your primary constraint is speed in pre-commit and CI, especially with monorepos. Go with Prettier if you need the deepest ecosystem support and can tolerate the slower runtime. Tell us your team size and whether you format in-editor or just in hooks for a clearer call.



   
ReplyQuote