-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Closed as duplicate of#138245
Closed as duplicate of#138245
Copy link
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage
Description
Branching on a boolean value is a very common operation in the Python VM, as all values are converted to booleans before any branch.
Checking for the truth of a boolean variable in the VM requires either dereferencing the pointer to get at the value or comparing with a full 64 bit pointer.
If we allocate the booleans in an array and align that array by 2*sizeof(PyLongObject) then we can determine the truth of the pointer by simply inspecting a bit in the pointer.
Instead of
ptr == Py_True or
ptr->ob_digits[0]
we can use a simple bitwise test:
((uintptr_t)ptr) & sizeof(PyLongObject)
Metadata
Metadata
Assignees
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage