# Third party library works slower inside Slicer's Python shell - why? how to do performance profiling?

**URL:** <https://discourse.slicer.org/t/third-party-library-works-slower-inside-slicers-python-shell-why-how-to-do-performance-profiling/18742>\
**Category:** Development\
**Tags:** performance\
**Created:** [July 15, 2021, 12:34am UTC](https://discourse.slicer.org/t/third-party-library-works-slower-inside-slicers-python-shell-why-how-to-do-performance-profiling/18742 "2021-07-15T00:34:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 15, 2021, 4:44am UTC](https://discourse.slicer.org/t/third-party-library-works-slower-inside-slicers-python-shell-why-how-to-do-performance-profiling/18742/2 "2021-07-15T04:44:10Z")

</div>

Lasio runs slower in Slicer because it logs a crazy amount of messages at debug level. You can disable this by temporarily decreasing the log level by running this command:

```python
import logging
logging.getLogger().setLevel(logging.INFO)

```

After you have finished with lasio, you can restore the log level to `logging.DEBUG`.

I haven’t experienced this with other Python packages, so you might report this finding to lasio developers. Maybe they could use their own logger instead of using the root logger (which is set to debug level logging in Slicer).

* * *

If you are curious how I’ve found out the root cause of the problem: with profiling. Profilers are invented exactly for pinpointing performance bottlenecks. I’ve used [cProfile](https://docs.python.org/3/library/profile.html) to collect logs and visualized the results using [tuna](https://github.com/nschloe/tuna).

Collect data:

```python
import cProfile
cProfile.run("las=lasio.read(r'c:\Users\andra\Downloads\A_Kerbel.las')", "c:/tmp/las.prof")

```

Plot results:

```python
pip_install('tuna')
slicer.util._executePythonModule("tuna", ["c:/tmp/las.prof"])

```

Tuna output:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/0/90e3f56d3559d6e705f130f9c50d79d2a6c4a336.png)

After adjusting the log level, the debug message logging function disappeared from the call tree and all the time-consuming functions make sense (they are complex and/or frequent operations):

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/1/81d583739ba71663acd30c2a82dde23695b7a616.png)

---

_[View the full topic](https://discourse.slicer.org/t/third-party-library-works-slower-inside-slicers-python-shell-why-how-to-do-performance-profiling/18742)._
