Hacker News new | ask | show | jobs
by rented_mule 8 days ago
I rewrote a C++ batch process in Python 1.4 (this was 1997) and the Python version was ~10x as fast.

The port was pretty direct, function for function. It was even line for line where language and library differences didn't offer an easier way. I was just trying to see if Python was so slow that we couldn't consider using it in production, and this was the most speed critical batch we had.

I assumed the speed difference was a bug that was skipping work, but that seemed unlikely because the output was correct. It turned out to be a bug in the C++ code that was needlessly reproducing work (an issue with cache keys). The bug was extremely subtle. When I fixed the C++, there was very little difference in speed as the batch was I/O bound when the cache was working.

So, adding to your point, sometimes you can greatly improve speed by rewriting in a slower language, even without performance in mind.

1 comments

To be technical about it, the Python program didn’t match the behavior of the c++ program. ;)

But also technically I think your point still stands. Because rewriting it helped you find a defect in the original. Which did improve performance of the original.

It’s quite interesting the two implementations performance was so close in the end. Do you consider one implementation “better” for non-performance reasons? Maybe one type of dev is easier to find. Or one language is easier to create and maintain correctly behaving programs in your environment?

The Python version was far easier to maintain and add features to. We kept it and rewrote other code in Python whenever we did significant work on it. All new back-end code was also written in Python after that.

Hiring devs who already knew Python was not really an option in 1997. But we quickly found that there was not much difference in time to ramp up a C++ developer on our C++ codebase vs. ramping up a developer on Python plus our Python codebase. It was just a matter of finding developers who were happy to learn a language they may or may not have heard of, but had likely never looked into.

Were you around for migration into python 2 or 3?
I was there for migrating to Python 2 and I don't remember much in the way of challenges, but Python 2 wasn't that big of a leap.

I was not there for Python 3, but I was at a larger place that had ~2 million lines of Python 2 code when the migration happened. It was much easier than I had expected. The two key differences from other stories I was hearing was that were a lot of automated tests (nearly 100K of them), and we had someone who was very good at writing parsers. He spent a few weeks automating the changes and getting tests to pass, and the night he ran the final conversion was remarkably clean. We never even used `six`.