Dev fixes O(N²) bug in DeepMind's mctx library, cutting MCTS overhead 3x
A developer training an AlphaZero-style AI agent for the game Factorio discovered that DeepMind's open-source mctx library was performing superlinearly during Monte Carlo Tree Search, with costs growing roughly five-fold when simulation count was merely doubled. Profiling revealed that XLA's GPU compiler was generating full copies of two large tree-state buffers — children_values and children_visits — on every iteration of the backward pass loop, because it could not safely prove in-place aliasing was valid. At 64 simulations, this produced around 345 MB of repeated buffer copies per move, causing per-simulation costs to double with each doubling of the simulation budget, a classic O(N²) pattern. The developer traced the root cause to a roughly 80-line function in mctx's tree-update logic and submitted a fix via pull request #116, rewriting the function to eliminate the redundant copies while producing bitwise-identical search results. The patch restored near-linear scaling and improved training throughput significantly without any change to search behavior.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in