This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author brandtbucher
Recipients AndersMunch, Dennis Sweeney, Kshitiz17, Mark.Shannon, brandtbucher, corona10, kj, rhettinger, serhiy.storchaka
Date 2021-06-14.16:34:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1623688440.51.0.0817537695348.issue44283@roundup.psfhosted.org>
In-reply-to
Content
Sorry, I’ve been out on vacation this weekend. I didn’t realize that there was already a PR for this… I’m honestly not sure that it’s totally ready yet.

While I absolutely agree that compiling efficient decision trees lies in our future, it certainly seems to me that using *both* strategies (decision trees and jump tables) would create the most efficient branching structure. In effect, our control flow would be a rose tree.

In your example, Mark, we could perform the checks for the integers 1 and 2 simultaneously, right?

Or consider a slightly more complicated example (simplified from PEP 636):

match …:
    case ["quit"]: …
    case ["look"]: …
    case ["get", obj]: …
    case ["go", direction]: …

We could compile this to something like:

- Check for Sequence.
- Multi-way jump on length.
- Multi-way jump on first item.

…which looks ideal to me.

I’m also confident that the jumping ops could also be broken up into fairly primitive instructions. A multi-way branch would just look something like:

(subject on TOS)
LOAD_CONST(<some hashable defaultdict>)
ROT_TWO
BINARY_SUBSCR
JUMP_FORWARD_TOS

…where only JUMP_FORWARD_TOS is new.

> For a sequence of integer constants, introducing the test `type(x) == int` at the start would allow you to convert the linear sequence of tests into a tree. Reducing `n` tests to `ln(n) + 1` tests.

Sorry, I’m having a bit of difficulty following this part. Is it something like the strategy I just described?
History
Date User Action Args
2021-06-14 16:34:00brandtbuchersetrecipients: + brandtbucher, rhettinger, Mark.Shannon, serhiy.storchaka, corona10, Dennis Sweeney, AndersMunch, kj, Kshitiz17
2021-06-14 16:34:00brandtbuchersetmessageid: <1623688440.51.0.0817537695348.issue44283@roundup.psfhosted.org>
2021-06-14 16:34:00brandtbucherlinkissue44283 messages
2021-06-14 16:34:00brandtbuchercreate