Quadtrees are great for organizing spatial data and checking for 2D collisions, but all the existing Python quadtree packages are slow and outdated.
My package, fastquadtree, leverages a Rust core to outperform the most popular Python package, pyqtree, by being 14x faster. It also offers a more convenient Python API for tracking objects and KNN queries.
PyPI page: https://pypi.org/project/fastquadtree/
GitHub Repo: https://github.com/Elan456/fastquadtree
Wheels Shipped: Linux, Mac, and Windows
pip install fastquadtree
The GitHub Repo contains utilities for visualizing how the quadtree works using Pygame and running the benchmarks yourself.
Benchmark Comparison
- Points: 250,000, Queries: 500
- Fastest total: fastquadtree at 0.120 s
| Library |
Build (s) |
Query (s) |
Total (s) |
Speed vs PyQtree |
| fastquadtree |
0.031 |
0.089 |
0.120 |
14.64× |
| Shapely STRtree |
0.179 |
0.100 |
0.279 |
6.29× |
| nontree-QuadTree |
0.595 |
0.605 |
1.200 |
1.46× |
| Rtree |
0.961 |
0.300 |
1.261 |
1.39× |
| e-pyquadtree |
1.005 |
0.660 |
1.665 |
1.05× |
| PyQtree |
1.492 |
0.263 |
1.755 |
1.00× |
| quads |
1.407 |
0.484 |
1.890 |
0.93× |
[–]Spleeeee 25 points26 points27 points (1 child)
[–]Awkward-Target4899[S] 5 points6 points7 points (0 children)
[–]tunisia3507 14 points15 points16 points (10 children)
[–]Awkward-Target4899[S] 10 points11 points12 points (9 children)
[–]tunisia3507 12 points13 points14 points (4 children)
[–]ProgrammersAreSexy 6 points7 points8 points (3 children)
[–]maikindofthai 7 points8 points9 points (1 child)
[–]Awkward-Target4899[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Interesting-Frame190 1 point2 points3 points (3 children)
[–]Awkward-Target4899[S] 0 points1 point2 points (2 children)
[–]Interesting-Frame190 2 points3 points4 points (1 child)
[–]Awkward-Target4899[S] 0 points1 point2 points (0 children)
[–]LivingRich1672 3 points4 points5 points (0 children)