﻿# ONNX Runtime large-graph startup: a wide ready set can make topological sorting expensive

The 1.32 topological-sort change targets wide ready sets during initialization; preserve visit ordering and measure graph structure, not only node count.

Author: Retrivium team
Updated: 2026-11-15
Canonical URL: https://retrivium.ai/journal/week46-engine-ort-topological-ready-queue-heap/
Language: en

ONNX Runtime 1.32.0 includes a session-creation change replacing a sorted-list ready set with a priority queue in topological sorting. The linked PR targets graphs with many simultaneously ready nodes, including constants. The important shape here is graph width and ordering work, rather than a neural tensor’s dimensions or the model’s parameter count.

## A chain and a wide graph stress different work

A long dependency chain may keep only a few nodes ready at once. A graph with many independent constants can fill the ready set immediately. Linear insertion into a sorted list behaves differently in those cases. A proposed scaling test keeps node count comparable while varying dependency width, recording sort time separately. This distinguishes the data-structure mechanism from a generic statement that all big graphs are slow to initialize.

## A heap must preserve the intended priority

The PR explains that the comparator’s tie-breaking preserves visitation order under the new structure. That property matters because an initialization optimization should not introduce arbitrary ordering changes as a side effect. A proposed unit check compares emitted node sequences on tied-priority and mixed-priority graphs. Numerical model outputs are still useful, but they may not reveal changed planning order when several valid topological orders happen to compute the same result.

## Repeated graph views amplify the cost

Upstream notes that graph viewers perform sorting and can be constructed by multiple transformers. A moderate per-sort cost can therefore accumulate across session creation. Profile total invocation count as well as individual sort duration. A benchmark that runs the sort once may explain complexity but understate its actual initialization share, while a full startup number alone can hide why a seemingly small container replacement mattered.

## Do not turn one stress case into a universal ratio

The PR reports dramatic improvement for constant-heavy large graphs alongside other changes. Those numbers are attributed examples, not predictions for another model. This article reports the ready-set mechanism and proposed structural controls without new timings. A correct local conclusion links width, sort frequency and startup time, while keeping steady-state inference performance separate from the initialization work that changed.

## Sources

- [ONNX Runtime v1.32.0 release](https://github.com/microsoft/onnxruntime/releases/tag/v1.32.0)
- [ONNX Runtime pull request #33939](https://github.com/microsoft/onnxruntime/pull/33939)

## Related reading

- [ONNX Runtime offline optimization: a saved optimized graph inherits a target contract](/journal/fg2-onnxruntime-offline-graph-target-compatibility/)
- [ONNX local functions: copy domain bindings and operator imports with the body](/journal/fg2-onnx-local-function-domain-opset-binding/)
