Skip to content

geohack rust

One of my oldest (first commit: 2013-06-24) tools is geohack, which was majorly improved by Egil Kvaleberg, who also co-maintained it. The tool is not only old but popular; many Wikipedia languages, including English and German, link to it from basically every page that uses coordinates.

Its popularity recently became a problem; it exceeded the maximum resources a tool on Toolforge can summon, hitting 60 requests/sec. using four separate copies of itself (4 CPUs).

Memory usage PHP -> Rust

So I obeyed the mantra of current technology, and rewrote it in Rust. Running its own webserver, the Rust version caches the various templates it uses, and does not require Toolforge disk or database access. First indications are that resource usage is massively down; a single copy/CPU can answer the incoming request deluge. Also, memory usage has dropped from 1.5GB to ~0.1GB.

The rewrite of the tool was done in very “literal” fashion, to preserve all corner case functionality where possible; indeed, the Rust version generates the exact output (not counting irrelevant whitespace and floating point rounding issues) as the PHP version. Eighteen examples from the PHP version, including locations on other planets and asteroids, now serve as Rust unit tests.

 

All this came at the cost of sometimes awkward Rust style. I am working on refactoring the code to make it more maintainable. Pull requests are always welcome, as are git issues and feature requests.