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

Case Study: Ecto (Elixir Data Mapping & Query DSL)

Analyzing 104 Elixir BEAM modules in 0.65 seconds: 3 @spec bugs, 7 unused private parameters, and a portable .pplt for Ecto

#elixir #prisma #ecto #static-analysis #typespecs #pplt #oxbow-code
Target Project
Prisma Check
0.65s (0.80s CPU)
Dialyzer Check
2.28s (5.14s CPU)
Cache (.pplt vs .plt)
173 KB vs 2000 KB
True Warnings
10 vs 9

In this case study, we run Prisma over Ecto, Elixir's flagship data-mapping and language-integrated query toolkit. With 58 .ex source files compiling into 104 BEAM modules full of macros, protocols, structs, recursive Macro.t() ASTs, and complex @spec contracts, Ecto is a demanding real-world stress test for Elixir static analysis.

Using Prisma's hybrid analyzer (v0.2.4) on Elixir 1.20.4 / OTP 29, the entire Ecto codebase is checked in 0.65 seconds (0.631s–0.689s). Prisma surfaced 3 real @spec inconsistencies and 7 unused private-function parameters (oxbow_code) that Elixir 1.20's compiler left unreported. All fixes and a portable ecto_3.15.0-dev.pplt (173 KB) have been submitted upstream in elixir-ecto/ecto#4817.


1. Execution Metrics & Summary

Metric Value
Source files / BEAM modules 58 .ex / 104 .beam
Elixir / Erlang runtime Elixir 1.20.4 / OTP 29 (ERTS 17.1.1)
Prisma check wall time (hybrid) 0.65 s (0.631s – 0.689s, 0.80s CPU)
Dialyzer check wall time (warm PLT) 2.28 s (5.14 s CPU, +21.14 s initial PLT build)
Portable .pplt vs Dialyzer PLT 173 KB (ecto_3.15.0-dev.pplt) vs 2,000 KB
Elixir 1.20.4 compiler warnings in lib/ 0
Dialyzer warnings in lib/ecto/ 9 (including changeset.ex:2664 && false positive; missed all 3 @spec bugs & 7 oxbow_code)
Prisma findings resolved 10 (3 @spec mismatches + 7 oxbow_code)
Post-fix mix test 1649 passed (97 doctests, 1552 tests)
Post-fix prisma check (hybrid) 0 warnings

2. Why Elixir 1.20.4 Missed These Findings

Compiling Ecto with Elixir 1.20.4 produces 0 type warnings across lib/ (only 3 intentional error-case warnings in test/). That is expected given Elixir's current gradual set-theoretic type system roadmap:

  1. No @spec vs. body verification yet: Elixir 1.20 infers types from patterns and guards inside a function, but does not cross-check traditional @spec attributes against the function body or callers.
  2. No structural dead-parameter analysis (oxbow_code): Unused parameters in private functions (defp) are not flagged when prefixed with _.

Prisma reads Elixir's debug_info directly from .beam files, checks @spec contracts in hybrid mode (strict gradual subtyping where specs exist, success typing where they do not), and runs structural oxbow_code reachability analysis on private functions.


3. Real Bugs & Cleanups Found in Ecto

A. @spec Mismatches (3)

  1. Ecto.Repo.Assoc.query/4 (lib/ecto/repo/assoc.ex:10)

    • Declared: @spec query([list], list, tuple, (list -> list)) :: [Ecto.Schema.t]
    • Actual: Every clause returns [list] ([], Enum.map(rows, fun) where fun :: (list -> list), and [load_assocs(item, refls) | sub_structs]), and Ecto.Repo.Queryable.execute/4 pipes the result straight into Ecto.Repo.Preloader.query/7, whose @spec expects [list].

    • Fix: Updated the return spec to :: [list].
  2. Ecto.Query.Builder.From.build/5 (lib/ecto/query/builder/from.ex:80)

    • Declared: @spec build(..., atom, ...) for the as parameter.
    • Actual: Immediately matches {:^, _, [as]} for runtime-interpolated aliases (from(p in Post, as: ^name)), which is a 3-tuple AST rather than an atom.
    • Fix: Widened as in @spec to atom | Macro.t().

  3. Ecto.Query.Builder.Join.build/10 (lib/ecto/query/builder/join.ex:155)

    • Declared & Actual: Same @spec narrowing (atom vs. {:^, _, [as]}).
    • Fix: Widened as in @spec to atom | Macro.t().

B. Unused Private Parameters (oxbow_code, 7)

All 7 findings are in private (defp) functions, so removing them preserves 100% of Ecto's public API and backwards compatibility:


4. What Ecto Taught Us About Prisma (v0.2.4)

Running Prisma against Ecto's heavy metaprogramming also exposed 6 real edge cases in Prisma itself, all fixed and covered by new tests in v0.2.4:

  1. Recursive types in tuple/list patterns: extract_tuple_elems/2, extract_list_elem/1, and list_tail_type/1 now treat unresolved/1 types (such as {recursive_ref, ...} in Ecto.Type.t()) as any instead of none, fixing false dead_code in Ecto.Type.dump/3 and load/3 for {:array, {:parameterized, _}}.
  2. Heterogeneous cons patterns [H | T]: bind_pattern({cons, _, H, T}, ...) now joins HT with extract_list_elem(TT) instead of assuming the whole list has H's type (e.g. [Access, :get] in Ecto.Query.Builder).

  3. Elixir multi-when guards: when G1 when G2 in Elixir elixir_v1 AST is a disjunction ([[G1], [G2]]), not a conjunction ([[G1, G2]]), eliminating false dead_code in Ecto.Query.Builder.escape/5.
  4. Open map updates (%{m | k: v}): update_map_type/2 on any_map or unresolved bases now preserves openness (any_map) rather than collapsing into a closed map with only the updated keys (Ecto.Query.Planner.plan_subquery/6).

  5. Elixir macro hygiene & intrinsics: &&/|| expansions (x@...@Elixir.Kernel) are recognized as macro-generated clauses in infer_case, and Enum.__in__/2 (-> boolean()) and IO.warn/1,2 (-> :ok) are modeled directly.

  6. Raise-only stub functions: prisma_oxbow now exempts private stub helpers where every clause unconditionally raises/errors (such as Ecto.Query.API.doc!/1 and Ecto.Query.WindowAPI.doc!/1).

5. Performance Comparison: Prisma vs. Dialyzer on Ecto

Running both tools on the same 104 Ecto BEAM modules on Apple Silicon:

Metric Dialyzer (OTP 29) Prisma v0.2.4 (hybrid)
Initial PLT / .pplt build 21.14 s < 0.2 s
Warm check wall time 2.28 s 0.65 s (0.631s – 0.689s)
Warm check CPU time 5.14 s (4.42s user + 0.72s sys) 0.80 s (~0.57s user + 0.23s sys)
Artifact size on disk 2,000 KB (PLT) 173 KB (ecto_3.15.0-dev.pplt)
Findings in lib/ecto/ 9 warnings (incl. changeset.ex:2664 && false positive; 0 @spec bugs) 10 real findings (3 @spec bugs + 7 oxbow_code)

Open-Source Regression Check (v0.2.0 vs. v0.2.4, 3 runs)

Corpus v0.2.0 (14f26c0) v0.2.4 Notes
prisma (ebin/*.beam) 0.340s – 0.660s 0.440s – 0.464s 0 warnings
jsone (ebin/*.beam) 0.250s – 0.259s 0.274s – 0.281s 0 warnings
saxy (ebin/*.beam) 0.372s – 0.397s 0.478s – 0.558s 0 warnings
ecto (104 modules) 0.507s – 0.562s 0.631s – 0.689s 0 warnings

👉 elixir-ecto/ecto Pull Request #4817