Summary

Idea: numeric dispatch with switch

Metadata

Attachments

Description

Just a note to myself so I don't forget:

Get rid of the nested ifs in number dispatch by combining the headers of objects and then dispatching on the result using `switch`.

The mechanics would be a little bit ugly but possibly it's faster. Even if it isn't faster, it might be more readable.

Something like:

 switch(COMBINE_TYPES(a, b)) {
 case FIXNUM_FIXNUM:
    blabla
    break;
 case FIXNUM_FLONUM:
    blabla
    break;
 ....
 }

Changes and comments

[2021-08-03 15:16:25 UTC] sjamaan attached numeric-type-hash-switches.patch (description=Initial version of switch-based numeric type dispatch)

[2021-08-03 15:17:48 UTC] sjamaan wrote:

I was unable to get a performance gain when doing this with nested switches. This is a clean version as there are no hacks involved to get the combined hashing for two types. If we decide to do it for readability, this first version is probably the one we want to apply.

[2021-08-03 16:17:03 UTC] sjamaan attached numeric-type-hash-switches-dyadic-procs.patch (description=Incremental diff to add hashing for two argument types simultaneously)

[2021-08-03 16:18:16 UTC] sjamaan attached numeric-type-hash-full-change.patch (description=Full patch for switch-based dispatching, for both single and dual-argument procedures)

[2021-08-03 16:19:41 UTC] sjamaan wrote:

Attached are patches (one is incremental on top of the earlier one, and one is a full patch for everything).

It appears to be a tiny bit faster (presumably due to being less branchy, since the code is doing more because we need to shift to "compact" the hash so that we can combine two hashes), but it could just be benchmark noise.

[2022-10-21 16:17:57 UTC] sjamaan changed status from new to closed

[2022-10-21 16:17:57 UTC] sjamaan set resolution to wontfix

[2022-10-21 16:17:57 UTC] sjamaan wrote:

The results were not very convincing and the patches messy, let's drop this idea.