inheriting a large python code base
rgacote at appropriatesolutions.com
Sat Feb 15 19:04:43 CET 2014
Some personal thoughts on how I've approached similar situations:
Step 0: Put all that code under version control immediately.
Being able to track and back-out changes is extremely useful -- even in a small, single-coder app.
With something this big, you'll find "things suddenly stopped working" as you make changes, and
being able to back-track your changes is invaluatable.
Step 2: Ask, "Why do you want to optimize the code (run faster)?"
- what is slow?
- loading data?
- solving specific problem?
- running specific functionality?
- specific calculations?
- network access?
- database access?
- small data sets?
- large data sets?
- who says it is slow?
and what is their definition of sufficiently quick?
3: You state you do not understand the internal logic.
I've also inherited applications where the internal logic was unclear.
Writing unit and functional tests (if they do not exist) will help to ensure you do not change the behavior of the application.
You may find that understanding the internal logic is the best way to speed-up the application.
You'll likely find that the biggest speed improvements come from optimizing the logic -- not the Python.
4: This is a personal prefernce when inheriting large code chunks -- and I'm sure some will counter it is not optimum.
Go through the code and run pep8 and pyflakes (or flake8) on all the code and address the issues that come up.
Aside from bringing the code into styling conformance, I find that this helps me to familiarize myself with the code.
As you're making style changes, review individual functions and add documentation if it is missing.
If you're not clear what a function does, mark it as such so you know to look at it carefully in the future.
5: Now you have a clean set of code -- most of which you've at least visually scanned -- and you're
ready to create some timing tests and dig into specifics.
----- Original Message -----
From: "Rita" <rmorgan466 at gmail.com>
To: python-list at python.org
Sent: Saturday, February 15, 2014 12:10:33 PM
Subject: inheriting a large python code base
i just inherited a large python code base and I would like to optimize the code (run faster). The application is a scientific application so I really don't understand the internal logic.
Here is what I have done so far, profile (cProfile) and was able to see where the code was taking the longest time.
I was wondering if anyone else experienced something like this and how they overcame a problem such a this…what techniques have you used to "optimize" the code.
--- Get your facts first, then you can distort them as you please. --
Ray Cote, President
Appropriate Solutions, Inc.
We Build Software
More information about the Python-list