Conference Presentation
Jane and the Compiler
Jane Street's OCaml Adoption and Ecosystem Evolution
Organizational History and Adoption
- Jane Street's adoption of OCaml began as an unplanned, tactical decision 15–16 years ago by the speaker, initially for quantitative research to replace slow Python code.
- The initial OCaml codebase grew to 80,000 lines and, despite being "terrible" by modern standards, formed the core of the firm's production infrastructure.
- In 2005, the firm made a strategic shift to integrate OCaml into permanent infrastructure, replacing a legacy system built primarily on VBA and Excel.
- By 2006, the development team consisted of approximately 10 OCaml programmers.
- By 2009, the team expanded to roughly 30 OCaml programmers, focusing on automated trading systems.
- In 2010, the firm began teaching traders to program in OCaml, shifting the user base from full-time engineers to part-time technical users and creating new pressures on language usability.
- Around 2015, Jane Street established a dedicated organization for compiler and tool development, marking a transition from passive user to active contributor in the OCaml ecosystem.
- The firm currently employs approximately 800 people and maintains a codebase of roughly 12 million lines of OCaml.
Strategic Drivers for Language Selection
- Performance Predictability: Unlike languages with complex runtime optimizers (e.g., SQL query optimizers) that obscure execution plans, OCaml provides predictable performance semantics, allowing engineers to reason about execution time without hidden optimizations.
- Safety and Correctness: The language's rich type system acts as a critical safety net for high-stakes financial trading, reducing the probability of catastrophic runtime errors caused by human oversight.
- Productivity and Learnability: As the organization scaled, the ability to easily navigate codebases and the interactive exploration provided by tooling became essential for new hires and part-time traders.
- Tooling Maturity: The firm prioritizes languages where tooling (IDE support, debugging, formatting) supports rapid iteration and error detection, moving away from the "Stockholm Syndrome" of accepting poor tools for niche languages.
Key Language Features and Evolving Capabilities
- First-Class Modules: Introduced by the community without Jane Street's direct request, this feature allowed modules (previously static compile-time constructs) to be treated as dynamic values, enabling more flexible component composition and eliminating manual wiring in complex systems.
- Generalized Algebraic Data Types (GADTs): Provided type-level precision that enabled:
- Safe memory layout control for high-performance packet processing systems.
- Modeling of existentially quantified types for message-oriented architectures.
- PPX (Preprocessor eXpressions): Replaced the previous Caml-P4 metaprogramming system to rationalize tooling by treating macros as functions operating on Abstract Syntax Trees (ASTs) rather than concrete syntax extensions.
- Merlin: An IDE-like tool for type inference and navigation, initially overlooked but now considered critical for code discoverability as the organization grew beyond a small team.
- Polymorphic Variants: Adopted early (circa 1995); usage has decreased recently as other type-directed inference techniques have rendered them less necessary for code concision.
Core Engineering Contributions and Projects
- Space-Time Debugger: A memory debugging tool developed with OCaml Labs that tracks heap allocations to unique stack traces, providing "flame graph"-style insights into memory usage without the overhead of full stack traces on every object.
- F Lambda (New Intermediate Representation): A compiler IR project designed to enable more aggressive and predictable inlining, allowing the compiler to eliminate unnecessary memory allocations by analyzing code across larger scopes.
- The current version of F Lambda often yields 10–20% performance improvements.
- A second version (F Lambda 2.0) is targeted for release by the end of the next year to further optimize zero-allocation coding disciplines.
- Improved Debugging Integration: Ongoing work to enhance GDB integration, including compiler-level instrumentation and debugger extensions, to enable value inspection and function execution during debugging sessions.
- Modular Implicit: A multi-year project implementing a disciplined version of type classes to allow implicit type resolution and reduce code verbosity.
- Typed Algebraic Effects: An experimental feature to track and separate side effects from pure code, enabling custom scheduler implementations and better concurrent programming models.
- Dune Build System: Open-sourced from the internal "Jenga" tool; it has become the most popular and fastest-growing OCaml build system, replacing the legacy "jbuilder" and serving both internal and external community needs.
Philosophy on Ecosystem Stewardship
- Conservative Language Evolution: Jane Street advocates for the OCaml community to avoid " PhD inflation" where features are added solely for academic papers; the language has evolved conservatively to avoid accumulating regrettable features.
- Ecosystem Dependency: The firm acknowledges a "break it, you bought it" responsibility, recognizing that their 12-million-line codebase depends on the long-term viability and vibrancy of the open-source ecosystem.
- Talent Retention Strategy: Active contribution to the language is viewed as essential for attracting top talent, preventing the perception of OCaml as an obsolete or "hated" technology (i.e., avoiding the "COBOL" scenario).
- Open Source Collaboration: The firm actively merges internal tools (like Dune) with external contributions to standardize the developer experience, improving usability for both internal engineers and the broader community.
Technical Q&A Highlights
- Native Code Compilation: The OCaml native code compiler (
ocamlopt) has been highly performant since the language's inception, using a simple, straightforward compilation strategy that generates efficient machine code without aggressive, complex optimizations. - JavaScript Backend (js_of_ocaml): A shockingly effective JS backend written by the creator of the OCaml object system, which preserves OCaml's memory model effectively; Jane Street did not build this but adopted it later.
- Compiler Education: The speaker notes a lack of high-quality, comprehensive guides specifically for understanding the OCaml compiler internals, despite the existence of general compiler theory resources like "Types and Programming Languages."