Using Rust to corrode insane Python run-times (2021)
vortexa.com
vortexa.com
An interesting thing they didn't mention is that Matplotlib's point-in-path code is actually already in C. So this isn't really a case of Rust being X times faster than Python, it's X times faster than some other C algorithm. That's probably why X is only ~4 (they don't actually give a single-thread comparison), instead of ~50.
https://github.com/matplotlib/matplotlib/blob/cb487f3c077c93...
I expect the Rust code is faster because that code is waaaaay more complicated than what they probably need (https://stackoverflow.com/q/11716268/265521) - e.g. it handles stroke widths.
IMO this result is not very interesting.
Related: - Quatree - RTree - BVH - Grid
Quadtree is one option, and would be my choice for 2D. Most people seem to prefer other structures for various reasons. You may also look at BSP trees, BVH or nested Bounding Boxes. There are others as well.
Is the set of ship positions and watched polygons entirely different from run to run? If not, it should be possible to go much faster than even the new rust based approach that takes 6 hours.
I would have used a postgres database with a PostGIS spatial index.
There’s the right way, the wrong way, and the Max Power way. Wrong but faster!
I have this thing I do where I'm using a json file basically as a database. Doing it with pure python was annoyingly slow so I wrote a simple(ish) wrapper around the boost::property-tree library (which does xml and json as both are needed for the project) and have been happily chugging along for years now.
I do wonder how much easier it would be to do the same thing in rust as I've found half the battle is tracking object/class lifetimes across the C-API barrier. As a side note, I'm also really good at hunting down segfaults...
Try this from pypi. Its a big boost when dealing with json in python.
> 1. Try breaking the data into chunks, and then using multi-processing (ugly in Python) to leverage a more powerful cloud virtual machine, sticking with matplotlib
> 2. Write a very small native custom library to do the math we want, using threads
There are a many more ways you could try to go about this, off the top of my head: numba, pypy (or other alternative python), jax/torch/tensorflow, multiprocessing, joblib.
On the other hand multiple dispatch and the way imports are handled left me quite confused as a beginner.
But it's powerful and also very fast, especially for plots.
There are at least a dozen languages that this would be easier in… depending on your background.
My immediate reaction was to try just annotating ctypes and see what performance delta exists
You might be thinking of Servo, which is a (purely?) Rust rendering engine that Mozilla abandoned, though it's not completely dead.
1. I don't know if Rust is being used in Firefox today (edit: turns out it is, see my sibling comment), but I can imagine why they wouldn't: Mixing C++ and Rust is probably non-trivial with the kind of portability they're aiming for. A lot of the UI and "business" logic in Firefox is, and has pretty much always been, implemented in JS and XUL (which was also available to extensions before WebExtensions, which is why Firefox extensions could back then change almost anything about the browser). So with JS available for a lot of the logic, Rust is probably mainly interesting for replacing the lower level C++ parts.
2.Back when Rust was created, it was used in a project called Servo - a new browser engine. To my knowledge there were never concrete plans to switch Firefox over to that engine, but Firefox adopted a lot of the techniques they pioneered. Mozilla was a different organisation back then, happy to experiment with no clear path to revenue. I didn't find any of those developments too surprising. I'm definitely not surprised they don't undertake a major incremental rewrite these days where it's more about fast profitability.
On a meta-level, I think the story that people like to tell is that Mozilla chose increasing executive compensation rather than using the same money to keep the Servo (and people working on Rust itself) employed.
[0]: https://servo.org
Narrator: It wasn’t the original use case.
Several options are available with JIT and AOT toolchains, alongside REPL programming environments.