D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14809 - Avoid costly dynamic cast from all class/interface upcasts
Summary: Avoid costly dynamic cast from all class/interface upcasts
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2015-07-19 12:45 UTC by Kenji Hara
Modified: 2024-12-13 18:43 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2015-07-19 12:45:33 UTC
This is a possible optimization for the common interface casts. But it requires a breaking of not well known small assumption.

In git-head (f78b25c9fb00bf024cd1d6e394f696bba4f2187b), issue 1747 and issue 2013 has been fixed properly. With the latest dmd:

interface IA {}
interface IB {}

interface IC : IB, IA {}

interface ID : IC {}
interface IE : IC {}

// C instance layout with -m32:
// ofs:   8   12  16  20
//        IB, IA  IB, IA
//        IC      IC
class C : ID,     IE
{
}

void main()
{
    C c = new C();

    ID id = c;  // class to base interface: static cast
    IE ie = c;  // class to base interface: static cast

    IC ic1 = id;    // intreface to 1st base interface: static cast
    IC ic2 = ie;    // class to base interface: static cast
    assert(ic1 !is ic2);
    // ic1 and ic2 are not identical, but they points same vtbl.
    // therefore any member function call via them will work.

    IA ia1 = ic1;   // interface to 2nd base interface: dynamic cast!
    IA ia2 = ic2;   // interface to 2nd base interface: dynamic cast!
    assert(ia1 is ia2);
    // By the dynamic cast, two IA will be identical.
    // However, like to the ic case, it's inherently unnecessary.
}

If we can agree to allow to fail the last assert(ia1 is ia2), we can remove costly dynamic cast from all class/interface upcasts.
Comment 1 dlangBugzillaToGithub 2024-12-13 18:43:48 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19017

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB