Repository navigation
Make implicit boolean conversions explicit #106008
Copy link
Copy link
Closed
Labels
3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage
Description
Activity
- addedperformancePerformance or resource usagePerformance or resource usageinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)3.13only security fixesonly security fixes
on Jun 23, 2023 @brandtbucher Apparently this PR introduced a refleak in test_grammar:
Raised RLIMIT_NOFILE: 256 -> 1024 0:00:00 load avg: 14.52 Run tests sequentially 0:00:00 load avg: 14.52 [1/1] test_grammar beginning 9 repetitions 123456789 ......... test_grammar leaked [2, 2, 2, 2] references, sum=8 test_grammar leaked [2, 2, 2, 2] memory blocks, sum=8 test_grammar failed (reference leak) == Tests result: FAILURE == 1 test failed: test_grammar Total duration: 349 ms Tests result: FAILUREThe previous commit builds correctly:
❯ git checkout HEAD^ Previous HEAD position was 7b2d94d8751 GH-106008: Make implicit boolean conversions explicit (GH-106003) HEAD is now at 6e9f83d9aee GH-106250: Support insts using one cache entry and no oparg (GH-106252) ❯ make -j -s ... ❯ ./python.exe -m test test_grammar -R : Raised RLIMIT_NOFILE: 256 -> 1024 0:00:00 load avg: 11.57 Run tests sequentially 0:00:00 load avg: 11.57 [1/1] test_grammar beginning 9 repetitions 123456789 ......... == Tests result: SUCCESS == 1 test OK. Total duration: 342 ms Tests result: SUCCESScan you take a look?
Huh. Yeah, I'll take a look.
Ah, I think I found it.
- added a commit that references this issue
on Jul 5, 2023
Metadata
Metadata
Assignees
Labels
3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage
...as discussed in faster-cpython/ideas#568.
By adding a dedicated instruction for converting values to bool, we can easily specialize the conditions of all remaining branches in the bytecode while keeping the branches themselves as "dumb" and simple as possible.
This is one of the few remaining common cases where a little specilization will give us a lot of useful information (such as "this branch won't execute arbitrary code") for higher tiers of optimization. Plus, the most common specializations (such as for
boolorNone) will be effectively no-ops.Linked PRs
Nonecomparisons #106367