Skip to content

Commit 37b98cc

Browse files
author
Adam Hrbac
committed
Profile whether a generator creates a coroutine
Since the vast majority of generators only ever end up creating one or the other, a condition profile significantly speeds up generator creation
1 parent 4f0adb3 commit 37b98cc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorFunctionRootNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.oracle.truffle.api.RootCallTarget;
5454
import com.oracle.truffle.api.frame.FrameDescriptor;
5555
import com.oracle.truffle.api.frame.VirtualFrame;
56+
import com.oracle.truffle.api.profiles.ConditionProfile;
5657
import com.oracle.truffle.api.source.SourceSection;
5758
import com.oracle.truffle.api.strings.TruffleString;
5859

@@ -63,6 +64,7 @@ public class PBytecodeGeneratorFunctionRootNode extends PRootNode {
6364
@CompilationFinal(dimensions = 1) private final RootCallTarget[] callTargets;
6465

6566
@Child private PythonObjectFactory factory = PythonObjectFactory.create();
67+
private final ConditionProfile isIterableCoroutine = ConditionProfile.create();
6668

6769
@TruffleBoundary
6870
public PBytecodeGeneratorFunctionRootNode(PythonLanguage language, FrameDescriptor frameDescriptor, PBytecodeRootNode rootNode, TruffleString originalName) {
@@ -85,12 +87,11 @@ public Object execute(VirtualFrame frame) {
8587
// if CO_ITERABLE_COROUTINE was explicitly set (likely by types.coroutine), we have to
8688
// pass the information to the generator
8789
// .gi_code.co_flags will still be wrong, but at least await will work correctly
88-
if ((generatorFunction.getCode().getFlags() & 0x100) != 0) {
90+
if (isIterableCoroutine.profile((generatorFunction.getCode().getFlags() & 0x100) != 0)) {
8991
return factory.createIterableCoroutine(generatorFunction.getName(), generatorFunction.getQualname(), rootNode, callTargets, arguments);
9092
} else {
9193
return factory.createGenerator(generatorFunction.getName(), generatorFunction.getQualname(), rootNode, callTargets, arguments);
9294
}
93-
9495
} else if (rootNode.getCodeUnit().isCoroutine()) {
9596
return factory.createCoroutine(generatorFunction.getName(), generatorFunction.getQualname(), rootNode, callTargets, arguments);
9697
} else if (rootNode.getCodeUnit().isAsyncGenerator()) {

0 commit comments

Comments
 (0)