Open
Description
Bug report
We have a test for our confidence that the trace is going the right way:
def test_confidence_score(self):
def testfunc(n):
bits = 0
for i in range(n):
if i & 0x01:
bits += 1
if i & 0x02:
bits += 1
if i&0x04:
bits += 1
if i&0x08:
bits += 1
...
But consider this:
def test_confidence_score(self):
def testfunc(n):
bits = 0
for i in range(n):
if i & 0x10:
bits += 1
if i & 0x20:
bits += 1
if i&0x40:
bits += 1
if i&0x80:
bits += 1
...
The direction of the branch changes every 16 iterations, so looks perfectly predictable to profiling but it as pathalogical as the first version.
How to fix this
We should lower our confidence a bit, even if profiling claims 100% predictability.
I don't think there is a perfect way to do this, but it shouldn't too hard to come up with something good enough.
Here is a possible scheme
Use lower confidence and threshold when generating the initial trace:
- 0.8 * profile_fraction + 0.1 for bool checks (maybe higher for
is None
checks) - 0.95 - 0.05 * misses recorded for type checks
- Stop trace at a lower confidence than before, say < 0.2
Reassess confidence in optimizer:
- Type information may raise confidence (it we eliminate a guard, we have 100% confidence)
- Stop trace at confidence < 0.33 (maybe allow a lower confidence if it completes a loop)