Instructor Notes

This is a placeholder file. Please add content here.

Introduction to Profiling


Instructor Note

The bottlenecked implementation was naively parsing a 10MB JSON file to create a list of unique items.

Repeatedly:

  • Checking the length of (C) strings, e.g. iterating till the terminating character is found, resolved by caching the results.
  • Performing a linear search of a list to check for duplicates before inserting, resolved by using an appropriate data structure (dictionary).
    • Allegedly duplicates were never even present in the JSON.

Why wasn’t this caught by one of the hundreds of developers with access to the source code?

Was more money saved by not investigating performance than committing time to profiling and fixing the issue?



Function Level Profiling


Instructor Note

It can help to run these examples by running snakeviz live. For the worked example you may wish to also show the code (e.g. in split screen).

Demonstrate features such as moving up/down the call-stack by clicking the boxes and changing the depth and cutoff via the dropdown.

Download pre-generated profile reports:



Instructor Note

Demonstrate this!



Instructor Note

Arguments 1-9 passed to travellingsales.py should execute relatively fast (less than a minute)

This will be slower via the profiler, and is likely to vary on different hardware.

Larger values should be avoided.

Download the set of profiles for arguments 1-10, these can be opened by passing the directory to snakeviz.

SH

python -m snakeviz .


Instructor Note

The default configuration of the Predator Prey model takes around 10 seconds to run, it may be slower on other hardware.

Download the pre-generated cProfile output, this can be opened with snakeviz to save waiting for the profiler.

SH

python -m snakeviz predprey_out.prof


Break


Line Level Profiling


Instructor Note

Download the pre-generated line_profiler output, this can be opened be to save waiting for the profiler.

SH

python -m line_profiler -rm predprey.py.lprof


Profiling Conclusion


Introduction to Optimisation


Instructor Note

  • Fixtures: A test fixture is a common class which multiple tests can inherit from. This class will typically include methods that perform common initialisation and teardown actions around the behaviour to be tested. This reduces repeated code.
  • Mocking: If you wish to test a feature which would relies on a live or temperamental service, such as making API calls to a website. You can mock that API, so that when the test runs synthetic responses are produced rather than the real API being used.
  • Test skipping: You may have configurations of your software that cause certain tests to be unsupported. Skipping allows conditions to be added to tests, to decide whether they should be executed or skipped.


Data Structures & Algorithms


Instructor Note

The important information for students to learn within this episode are the patterns demonstrated via the benchmarks.

This episode introduces many complex topics, these are used to ground the performant patterns in understanding to aid memorisation.

It should not be a concern to students if they find the data-structure/algorithm internals challenging, if they are still able to recognise the demonstrated patterns.



Break


Understanding Python (NumPy/Pandas)


Keep Python & Packages up to Date


Understanding Memory


Optimisation Conclusion