New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix compilation slowdown due to controlflow analysis #6146
Conversation
sklam
commented
Aug 18, 2020
•
edited
edited
- makes CFG computation lazier.
- replace backedge algorithm with a DFS based algorithm instead of dominator-based.
My current reproducer for issue #6133 from pprint import pprint
import numpy as np
import numba
body = """
for fi in range(0, 10):
data[fi] += 1
for index in range(0, 7):
idx = index
if idx % 2 == 0:
data[idx] += fi
else:
data[idx] += 1 if data[idx] < 3 else 2
data[idx] += 1
data[idx] += 1
"""
wrapper = """
def kernel(data):
{}
"""
source = wrapper.format(body * 100) # 75
glbs = {}
exec(source, glbs)
arg = np.zeros(100)
argtypes = (numba.typeof(arg),)
kernel = numba.njit(argtypes)(glbs['kernel'])
# 0.48.0 takes 24sec
# 0.51.0 takes 1min13sec
metadata = kernel.get_metadata(kernel.signatures[0])
timings = metadata['pipeline_times']['nopython']
sorttimings = sorted(timings.items(), key=lambda x: sum(x[1]))
for k, v in reversed(sorttimings):
print(f"{k:40} {sum(v):.3}") This prints the compiler passes in descending runtime. With the patch:
Without the patch:
So the patch trims 20 seconds from SSA |
Note: dominator-based version is too expensive.
264665e replaces the backedge algorithm with a simple but faster DFS version. This further speed up the SSA reconstruction:
(updated to use output from non-profiled run) |
Thanks for the patch. I tested this manually, locally, 10.4->4.73s change in SSA rebuild. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes look good, couple of minor comments.
numba/core/controlflow.py
Outdated
# A few derived items are checked to makes sure process() has been | ||
# invoked equally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can probably remove this comment now, process()
has little effect as everything is delayed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch.
Co-authored-by: stuartarchibald <stuartarchibald@users.noreply.github.com>
Resolved all comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes.
Fix compilation slowdown due to controlflow analysis