OCaml Code Optimization

This training was designed by OCamlPro to enable OCaml developers to extract maximum performance from the applications they write. Based on our team's direct involvement in the development of the OCaml compiler, this training shows how to write code that is optimally optimized and how to best use all the optimizations provided by the OCaml compiler.

Program

Performance on Modern Architectures

  • Quick assembler basics (for the following examples)
  • Architecture: Memory/cache hierarchy, Out-of-order execution, Prediction, Effects of decoded instruction caches
  • Consequences: Interpreting results from instruction sampling tools (perf), Interpreting microbenchmarks
  • Operating system and system calls: What is expensive, What is blocking

OCaml Runtime

  • Comprehensive overview of the garbage collector (GC) operation
  • Cost of different parts of the GC: Worst-case and average algorithmic costs, unusual effects, Example cases of unexpected effects
  • FFI (performance-relevant aspects): Allocations/invariants, Annotations [@...] / boxing, Roots

OCaml Compiler

  • Architecture: Tracking transformations of various constructs through compiler passes
  • Cost of language constructs
  • Guided tour of optimizations
  • Differences with C-like compilers/runtimes

Tools

  • perf and derived tools
  • Proper benchmarking: Analyzing the type of performance sought (speed/latency (average/worst)...), Analyzing benchmark statistics, Non-regression benchmarks
  • Valgrind/callgrind/cachegrind...
  • The gdb debugger

Approaches to Improve Performance

  • Using optimizations / choosing appropriate code structures: Controlling optimizations, Ensuring they apply
  • Translating parts into C-like code: Analyzing relevance, Effectively using the FFI
  • Identifying, recognizing, and fixing anti-patterns
  • Fixing memory leaks and over-allocations: Reducing lifetimes, List of leak types

Organizing Optimization in a Project

  • Estimating achievable performance for a program: Segmenting the program and separating analysis, Comparing with reality
  • Identifying meaningful optimizations: Prioritizing the most useful aspects, What not to optimize

Relevant / Non-Relevant Algorithms and Data Structures in OCaml

Next Sessions

    Sessions are organized on demand.

OCaml Code Optimization

Duration: 2 days Practice: 50%
Price: 2000 EUR/pers. excl. taxes
Pre-requisites
  • OCaml
  • Computers
Public
  • Developers
Pedagological Objectives
  • Performance on Modern Architectures
  • OCaml Runtime
  • OCaml Compiler
  • Tools
  • Approaches to Improve Performance
  • Organizing Optimization in a Project
  • Relevant / Non-Relevant Algorithms and Data Structures in OCaml
Quality Indicators
  • Mean satisfaction score: 18.5/20
  • Success Rate: 100%

Version: November 14, 2022

Pierre Chambart (OCaml)

Pierre has been an R&D engineer at OCamlPro since 2013, following a PhD in formal methods and a postdoc on web programming in OCaml. Pierre is a member of the OCaml compiler core team, specializing in optimized code generation. He is also one of the main developers of the Tezos blockchain in OCaml.

Vincent Laviron (OCaml)

Vincent has been an R&D engineer at OCamlPro since 2015. After working on adapting abstract interpretation techniques to OCaml, Vincent joined the team working on Flambda, the optimizing compiler for OCaml, and is now a member of the OCaml compiler core team.

Useful Information

Contact

You can contact us using the form on top of every course description, or by email at contact@ocamlpro.com.

Delayed access timeframe

Since our trainings are organised upon request within two months after the first contact, the access timeframe may vary depending on your specific needs and custom training conditions which will all be agreed upon prior to the course.

Registration and course modalities

Our courses may either be done remotely or physically.

Prior to the course:

  • Either a meeting or a survey to identify your needs and expectations.
  • Shipment of administrative papers such as: written agreement, welcome booklet and rules of procedure.
  • Shipment of everything required to guarantee the good conduct of the course: external ressources, and custom instructions alike.

During the course:

  • The attendee goes to the designated location with his/her personal computer.
  • Time slots for our on-site Inter Corporation Trainings are the following:
    • Start - 9:30AM
    • Lunch Break - 12:00PM to 01:00PM
    • End - 05:30PM
  • Evaluations throughout the duration of the course (quizzes, tests and experimentations).

End the course:

  • Presentation of a certificate of training.
  • Auto-evaluation quizz.
  • A hot feedback form on the quality of the course.

After the course:

  • A cold feedback form on your satisfaction (roughly three months after the course)

Methods used and modalities for evaluation

Our courses may welcome a maximum of ten attendees and the number of tutors may vary between one and two depending on the amount of practical tasks in the course.

Parameters such as the number of attendees and their overall skill level will affect pedagogical modalities such as the number of pratical tasks, guided discussions, collaborative development, etc.

Courses may include small projects to develop independently to help consolidate the acquired knowledge.

The ressources are written by the OCamlPro team prior to the courses. Documents are generally written in english and can be translated to french if need be.

We make the progress of our trainees and its evaluation a core aspect of our courses. Indeed, guaranteeing the durable acquisition of the skills at hand is key, especially for the newer comers. To that extent, we will have trainees undergo tailored group works, exercises and hands-on practice which modalities can all be customised to your specific needs.

Accessibility, handicap

Preliminary studies are done prior to every training to guarantee the quality of the course by tweaking the pedagogical modalities and take into consideration any handicap communicated during the first stages of the registration. We are at your disposal to answer your every question and other queries at: contact@ocamlpro