AbsInf: A Lightweight Object to Represent float('inf') in Dijkstra's Algorithm
Anjan Bellamkonda, Laksh Bharani, Harivatsan Selvam
TL;DR
The paper addresses the performance overhead of using Python's native infinity representation in Dijkstra's algorithm. It introduces AbsInf, a lightweight C-extension object that behaves as a symbolic infinity with constant-time dominance and arithmetic-neutral operations, and integrates it by replacing only the distance initialization. Across ten synthetic graph types and eight real-world routes, AbsInf delivers consistent speedups, averaging 9.74% and peaking at 17.2%, with Welch's t-test confirming significance (p = 0.0002175). The work demonstrates that domain-specific numeric abstractions can yield meaningful gains in interpreted languages, suggesting avenues for broader applications in performance-critical control flows and graph algorithms.
Abstract
We introduce AbsInf, a lightweight abstract object designed as a high-performance alternative to Python's native float('inf') within pathfinding algorithms. Implemented as a C-based Python extension, AbsInf bypasses IEEE-754 float coercion and dynamic type dispatch, offering constant-time dominance comparisons and arithmetic neutrality. When integrated into Dijkstra's algorithm without altering its logic, AbsInf reduces runtime by up to 17.2%, averaging 9.74% across diverse synthetic and real-world graph datasets. This optimization highlights the performance trade-offs in high-frequency algorithmic constructs, where a symbolic use of infinity permits efficient abstraction. Our findings contribute to the broader discourse on lightweight architectural enhancements for interpreted languages, particularly in performance-critical control flows.
