Skip to content

Commit fb7adaf

Browse files
authored
Add Strobelight example (#850)
1 parent c7db5be commit fb7adaf

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

657 KB
Loading

docs/source/optimization_guide/resolution.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,29 @@ enabled for production pipelines.
8787

8888
You can look for a particular function that's taking up significant
8989
portion of execution time.
90+
91+
One interesting way to use profiler is to check how often the GIL is held.
92+
The `take_gil() <https://github.com/python/cpython/blob/3.12/Python/ceval_gil.c#L331-L458>`_ function is resposible for acquiring the GIL.
93+
By organizing the stack around ``take_gil`` function, we can see what functions
94+
are competing for the GIL, and identify a potential bottleneck.
95+
96+
The following figure is an example of stacks sampled with Strobelight.
97+
It says that the pipeline spends 13% of the time trying to acquire the GIL.
98+
99+
.. image:: ../../_static/data/strobe_light.png
100+
101+
What stands out is that loading array data from NPZ file holds the GIL longest.
102+
Functions from I/O and preprocessing take up only 0.5% of the runtime for acquiring the GIL.
103+
But loading NPZ holds the GIL for more than 2.7% of the runtime.
104+
105+
This pipeline uses :py:func:`spdl.io.load_npz` to load the NPZ file.
106+
This function is more efficient than the official :py:func:`numpy.load` function,
107+
however, it only partially releases the GIL.
108+
109+
The `PR#849 <https://github.com/facebookresearch/spdl/pull/849>`_ is one of out attempts
110+
to make it fast and efficient.
111+
Another approach to resolve this is to change the file format.
112+
This NPZ file uses compressed format, and loading compressed NPZ file requires additional
113+
memory allocation and compute resource for decompression.
114+
If the storage space permits, re-creating the dataset without compression can help
115+
reducing the GIL contention.

0 commit comments

Comments
 (0)