C99实现的新的O(m log^(2/3) n)最短路径算法
C99 implementation of new O(m log^(2/3) n) shortest path algorithm

原始链接: https://github.com/danalec/DMMSY-SSSP

DMMSY 是一个高性能的 C99 单源最短路径 (SSSP) 算法实现,比传统的 Dijkstra 算法实现了显著的加速。该算法发表于 STOC 2025 会议论文,通过使用递归子问题分解代替全局优先队列,克服了 $O(m + n \log n)$ 的复杂度限制,达到了 $O(\log^{2/3} n)$ 的复杂度。 主要特性包括:通过手动内存管理实现零分配设计,优化的压缩稀疏行 (CSR) 布局,以及模块化架构以方便维护。基准测试表明,加速倍数超过 20,000 倍,尤其是在具有 250k–1M+ 节点的图上。 该项目提供了一个基准测试套件用于性能比较,并针对使用 Clang 优化的现代 x86_64 架构设计。它采用双许可模式(MIT 和 Apache 2.0),并欢迎贡献。核心逻辑非常精简(1M 节点约为 800ns),有效消除了排序瓶颈。

一位开发者danalec在Hacker News上分享了一个新的C99最短路径算法实现。该算法基于获得STOC 2025最佳论文奖的研究成果,复杂度为O(m log^(2/3) n),在稀疏有向图上优于传统的Dijkstra算法。 主要特性包括缓存优化的数据布局、零分配设计和递归子问题分解。据报道,在包含25万到100万节点的图上进行的基准测试显示,与标准Dijkstra实现相比,速度提升超过20,000倍,核心运行时间约为100万节点800纳秒。 开发者正在寻求关于边缘情况和潜在优化的反馈。一些评论者对这一进展表示兴奋,而另一些评论者则质疑基准测试结果,指出理论上的改进对于典型的图大小并不显著,且声称的速度提升似乎不太可能。 论文和GitHub仓库的链接已提供。
相关文章

原文

A high-performance C99 implementation of the Single-Source Shortest Path (SSSP) algorithm introduced in:

Ran Duan, Jiayi Mao, Xiao Mao, Xinkai Shu, Longhui Yin,
"Breaking the Sorting Barrier for Directed Single-Source Shortest Paths", STOC 2025.

DMMSY provides a robust and efficient backend for solving SSSP problems on large-scale sparse graphs. By leveraging a recursive subproblem decomposition rather than a strict global priority queue, this implementation breaks the long-standing $O(m + n \log n)$ complexity barrier, delivering speedups exceeding 20,000x over standard Dijkstra implementations.

Key Features

  • Breaking the Sorting Barrier: Reduces the complexity factor to $O(\log^{2/3} n)$, significantly outperforming $O(\log n)$ at scale.
  • Zero-Allocation Design: Careful manual memory management with pre-allocated workspaces to eliminate runtime overhead.
  • Cache-Optimized CSR Layout: High-density Compressed Sparse Row storage for maximum spatial locality.
  • Modular Architecture: Clean separation between common utilities, baseline Dijkstra, and optimized DMMSY implementations.
  • High-Precision Timing: Integrated platform-independent timing for stable performance reporting.

Tests conducted on a modern x86_64 architecture using Clang -O3 with LTO and Fast-Math optimizations.

DMMSY-SSSP Performance Dashboard

Note

DMMSY achieves its maximum performance delta on graphs with 250k–1M+ nodes. In the C implementation, the lean DMMSY execution logic (~800ns for 1M nodes) effectively eliminates the sorting bottlenecks found in traditional binary heaps.

The project requires a C99-compliant compiler (Clang recommended for Fat LTO performance).

clang -O3 -march=native -flto -DNDEBUG src/*.c -I include -o dmmsy_bench

Quick Start: Benchmarking a Random Graph

The main package provides a comprehensive benchmarking suite that generates random sparse graphs and compares performance across multiple algorithms.

#include "include/common.h"

int main() {
    // 1. Generate a sparse graph (1M nodes, 5M edges)
    CSRGraph g = random_graph(1000000, 5000000, 100.0);
    
    // 2. Prepare weight and predecessor arrays
    weight_t *d = malloc(sizeof(weight_t) * g.n);
    node_t *pr = malloc(sizeof(node_t) * g.n);

    // 3. Run the Dual-Interval Pivot SSSP
    ssp_duan(&g, 0, d, pr);

    // 4. Verify results against Dijkstra reference
    // ... verification logic ...

    free_graph(&g);
    return 0;
}
  • include/: Common header definitions and API interfaces.
  • src/common.c: Core data structures (CSRGraph, Fast4AryHeap).
  • src/dijkstra.c: Standard $O(m + n \log n)$ reference implementation.
  • src/dmmsy_opt.c: Optimized Duan–Mao–Mao–Shu–Yin algorithm.
  • src/benchmark.c: High-precision performance reporting and visualization driver.

Contributions are welcome! If you find a bug, have an optimization suggestion, or want to port to another architecture, please open an issue or pull request.

This project is dual-licensed under the MIT License and Apache License 2.0. See the LICENSE-MIT and LICENSE-APACHE files for details.

  1. Duan, R., et al. (2025). Breaking the Sorting Barrier for Directed Single-Source Shortest Paths. arXiv:2504.17033
  2. Dijkstra, E. W. (1959). A note on two problems in connexion with graphs. Numerische Mathematik.
  3. ACM Digital Library
  4. MPI-INF repository
联系我们 contact @ memedata.com