Prisma Logo Prisma v0.2.12
Back to Blog & Benchmarks
Case Studies benchmarks 2026-11-19 · Manuel Rubio OTP 29

Case Study: Padmark (Pure-Elixir Markdown Parser & HTML Transformer)

Replacing Dialyzer with Prisma across 81 BEAM modules: 8x faster cold builds, 5 real @spec and oxbow_code fixes, and an upstream PR to Elixir

#elixir #prisma #padmark #dialyzer #static-analysis #typespecs #pplt #oxbow-code
Target Project
Prisma Check
0.95s (1.52s CPU)
Dialyzer Check
2.13s (3.44s CPU)
Cache (.pplt vs .plt)
57 KB vs 2921 KB
True Warnings
10 vs 0

In this case study, we migrate Padmark — a pure-Elixir Markdown parser and HTML transformer with leex/yecc lexers and parsers (81 BEAM modules) — from Dialyzer (dialyxir) to Prisma.

Running both tools side by side on Elixir 1.20.4 / OTP 29.1.2 highlights two complementary differences: Dialyzer took 1m 18.57s on a cold PLT build (2.13s warm) and reported 0 errors, whereas Prisma completed its cold dependency PPLT build + analysis in 9.76s (0.95s warm) and uncovered 5 real issues — two @spec bugs (one causing dead_code) and three unused private-function parameters (oxbow_code) — plus an upstream Elixir stdlib spec imprecision in Regex.run/2 and Regex.scan/2 that we submitted in elixir-lang/elixir#16151.


1. Execution Metrics & Summary

Metric Dialyzer (dialyxir) Prisma (0.2.6 / 0.2.7)
Padmark BEAM modules 81 81
Elixir / Erlang runtime Elixir 1.20.4 / OTP 29 (ERTS 17.1.1) Elixir 1.20.4 / OTP 29 (ERTS 17.1.1)
Cold build + check (wall) 78.57 s (74.17s PLT + 1.50s check) 9.76 s (17 dep PPLTs + check)
Cold CPU (user / sys) 185.83s / 15.11s (255% CPU) 9.37s / 2.07s (117% CPU)
Warm check (wall) 2.13 s (1.62s analysis) 0.95 s (0.45s–0.52s analysis)
Warm CPU (user / sys) 2.68s / 0.76s (161% CPU) 0.87s / 0.65s (159% CPU)
Findings reported 0 10 (5 real + 5 Regex.run/3 spec union)
Post-fix mix test — 424 passed (59 doctests, 365 tests)

(Note: dialyxir also pulled in erlex as a transitive dependency; removing dialyxir unlocked both packages from mix.lock and replaced Dialyzer in .check.exs with mix prisma.)


2. What Prisma Caught That Dialyzer Missed

Dialyzer's success typing leaves wide or mismatched @specs silent as long as some execution path can succeed. Prisma's hybrid mode caught 5 genuine issues in Padmark:

A. @spec Mismatches & Dead Code (2)

  1. Padmark.Helpers.replace/4 (lib/padmark/helpers.ex:7)

    • Declared: @spec replace(String.t(), Regex.t(), String.t() | (... -> String.t()), Padmark.Options.options()) :: String.t()

    • Actual: Padmark.Helpers.replace/4 forwards options straight to Regex.replace/4, whose spec expects global: boolean() — not %Padmark.Options{} structs or maps.
    • Fix: Narrowed the 4th parameter spec to global: boolean().
  2. Padmark.Transform.transform/2 (lib/padmark/transform.ex:266) — dead_code

    • Declared: @spec transform(Padmark.ast(), Options.options()) :: String.t()
    • Actual: The docstring states it "also accepts the result of map_ast_with for convenience", and the very first clause is def transform({ast, _}, options). Because Padmark.ast() is a list, Prisma flagged that clause as unreachable (Function clause pattern cannot match).
    • Fix: Widened the first parameter spec to Padmark.ast() | {Padmark.ast(), term()}.

B. Unused Private Parameters (oxbow_code, 3)

  1. Padmark.Parser.Ast.Inline.footnote_link/3 (lib/padmark_parser/ast/inline.ex:397): _match (argument #2) was ignored across all clauses -> simplified to footnote_link/2.
  2. Padmark.Parser.Parser.ListParser._finish_list_item/3 (lib/padmark_parser/parser/list_parser.ex:195): _at_start? (argument #2) was ignored and forwarded through _finish_list_items/4 -> removed from both helpers.
  3. Padmark.Transform._make_att1/2 (lib/padmark/transform.ex:484): tag (_) (argument #2) was ignored -> simplified to _make_att1/1.

3. From a False Positive in Padmark to an Upstream Elixir PR

The remaining 5 findings in Padmark.Parser.LineScanner (lib/padmark_parser/line_scanner.ex) all came from calling Regex.run/2 (via regex_run(key, target) -> Regex.run(rgx_map(key), target, [])) and then passing the captured groups to String.length/1, String.trim/1, and String.starts_with?/2:

@spec run(t, binary, capture_opts) :: nil | [binary] | [{integer, integer}]
def run(regex, string, options \\ [])

Because Elixir defines Regex.run/2 via a default argument options \\ [], the 2-arity function inherited [{integer, integer}] in its return union — even though Regex.run/2 without return: :index can never return index tuples. Dialyzer stays silent because [binary] overlaps String.t(), whereas Prisma's gradual_mismatch rejects {integer(), integer()} | String.t() where String.t() is expected.

Running Prisma across Elixir's own lib/elixir/ebin (2.68s for the entire standard library) confirmed the same pattern in Regex.run/2 and Regex.scan/2, along with several unused private parameters (Calendar.ISO.zone_to_iodata/4, GenEvent.server_update/5, GenEvent.server_call_update/4, Registry.Partition.init_pid_ets/2, Code.Formatter.unary_op_to_algebra/5, and Code.Fragment.codepoint_cursor_context/2). Those fixes were submitted upstream in elixir-lang/elixir#16151.


4. Engineering Bonus Along the Way

Benchmarking padmark's dependencies and Elixir's standard library during this migration also surfaced two major performance bugs in Prisma itself: