Analyzing the Python import time output

Python offers the possibility to log the times associated to importing modules through python -X importtime .... The output offers a textual description of the nested modules and their respective loading times. Simon Willison noted that its analysis is impractical without a tooland he pointed out that https://kmichel.github.io/python-importtime-graph/ offers a visualization of the output that can be useful.

That tool is standalone and separate from any other experience. But what if we can bring it in the development environment?

Let's start with the output that Simon used in his experiment:

url := 'https://gist.githubusercontent.com/simonw/5b7ee41b5ee324105f23ee695d4c0906/raw/6b2e2055c40608aec2c6600eb64f401bd33a688b/llm.txt'.
output := ZnClient new get: url.
  

We have a simple implementation that parses that output and then creates a tree of GtPyImportTimePackage Object subclass: #GtPyImportTimePackage instanceVariableNames: 'localTime cumulativeTime nesting name children' classVariableNames: '' package: 'GToolkit4Python' . Inspecting the below snippet offers an inspector with a browsable view.

GtPyImportTimePackage fromString: output