JuliaCon 2025

Cox model go brrr: a journey to performance.
2025-07-23 , Main Room 3

The Cox model is a standard and very well studied parametric model for censored time-to-event data, relying on very strict proportional hazard assumptions. It is one of the core tools of survival analysis and requires numerical estimation of its coefficients. Our first implementation, using an off-the-shelf numerical solver, was correct but very slow compared to competition. We describe here the step-by-step procedure to performance that led us to our current top-of-the-line implementation.


The Cox model is a standard and well studied parametric model for censored time-to-event data, relying on very strict proportional hazard assumptions. It is one of the core tools of survival analysis, and benefits from many very good implementations (in Fortran, C or C++) interfaced from almost every language (in particular R and Python). It requires a numerical estimation of its coefficients through gradient descent, but the solving routines are well established nowadays.

We start by a very naive implementation using an off-the-shelf numerical solver, leveraging automatic differentiation. While very convenient, this solution was slow, and we decided to implement by hand the derivatives and hessian of the loss function to make it faster. Then, moving to our own solving loop instead of the off-the-shelf solver allowed us to reduce overhead. Finally, through profiling and reducing allocations, we were able to squeeze out the maximal performance without changing the algorithm itself. The final but crucial improvement comes from mathematical analysis of the loss function and led us to depart from standard Newton-Raphson minimization.

We discuss how Julia's ecosystem tools helped us at each step, in particular for type stability and allocations reductions, but also to build fair comparison with the competition directly on GitHub actions.

The result is an implementation of the Cox algorithm, a pillar of numerical survival analysis used in many other fields such as public health or medicine, that is faster than the historical R/C equivalent for large enough inputs. We hope this implementation will be released soon, with a correct and comprehensive API, in SurvivalModels.jl.

I am currently an associate professor in statistics in Marseille (France). Actuary by formation, I focus my researches on high dimensional statistics and dependence structures estimations, with a lot of applications in insurance, reinsurance, and more recently public health. I do have a taste for numerical code and open-source software, and most of my work is freely available on GitHub.