thenineteen / Semiology-Visualisation-Tool

Data driven 3D brain visualisation of semiology. Semiology to anatomy translator based on over 4600 patients from 309 peer-reviewed articles.
MIT License
9 stars 6 forks source link

Profiling #208

Closed thenineteen closed 3 years ago

thenineteen commented 3 years ago

Tested on SVT/Slicer in addition to benchmarking, using Head Version Right and Hypomotor Right: Overall saves upto 50%: 6-7 seconds from 14 seconds (maximum time saved if show progress while updating colors in slicer/SVT is disabled and use cache when available is enabled.)

Dealt initially with the largest bottlenecks:

thenineteen commented 3 years ago

Profiling How To

1. Capture profile output

Go to this commit ID fe37932e347c6b993c5c486d0832e4f3ded6717d (alternatively look at section below on how to add profiler)

Run slicer and your query, which should output svt.profile file to working tree

1.a Manually Adding Profiler

In SemiologyVisualisation.py add import cProfile to the top of the file and add this method:

    def updateColorsWithProfile(self):
        p = cProfile.Profile()
        p.runcall(self.updateColors)
        p.dump_stats('C:\\svt.profile')

Then update this line in def makeUpdateButton(self) from:

        self.updateButton.clicked.connect(self.updateColors)

to

        self.updateButton.clicked.connect(self.updateColorsWithProfile)

2. Use cprofilev to view profiler output

You can now pip install cprofilev and run cprofilev -f svt.profile to serve up the profiler result and browse through it like so: image

2. Alternatively, use qcachegrind to view profiler output with pretty trees

Or you can pip install pyprof2calltree and convert the profile file to calltree using pyprof2calltree -i svt.profile -o svt.calltree and then use qcachegrind (https://sourceforge.net/projects/qcachegrindwin/) to view svt.calltree image

thenineteen commented 3 years ago

QUERY_LATERALISATION calls to pivot_result_to_one_map are next to be made more efficient