Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Producing abstract types can be more expensive than leaftypes #13299

Closed
mauro3 opened this issue Sep 24, 2015 · 7 comments
Closed

Producing abstract types can be more expensive than leaftypes #13299

mauro3 opened this issue Sep 24, 2015 · 7 comments
Labels
compiler:codegen Generation of LLVM IR and native code

Comments

@mauro3
Copy link
Contributor

mauro3 commented Sep 24, 2015

Making a abstract type seems more expensive than a concrete one (although I didn't benchmark it):

julia> abstract A{T}; a() = A{Int}
a (generic function with 1 method)

julia> immutable B{T} end; b() = B{Int}
b (generic function with 1 method)

julia> @code_native a()
        .text
Filename: none
Source line: 1
        push    RBP
        mov     RBP, RSP
        push    RBX
        sub     RSP, 40
        mov     QWORD PTR [RBP - 40], 4
Source line: 1
        movabs  RBX, 140026519774896
        mov     RAX, QWORD PTR [RBX]
        mov     QWORD PTR [RBP - 32], RAX
        lea     RAX, QWORD PTR [RBP - 40]
        mov     QWORD PTR [RBX], RAX
        vxorps  XMM0, XMM0, XMM0
        vmovups XMMWORD PTR [RBP - 24], XMM0
Source line: 1
        mov     RDI, QWORD PTR [65703328]
        mov     RAX, QWORD PTR [RDI + 8]
Source line: 1
        lea     RSI, QWORD PTR [RBP - 24]
Source line: 1
        mov     RCX, QWORD PTR [169843264]
        mov     QWORD PTR [RBP - 24], RCX
        mov     RCX, QWORD PTR [65704528]
        mov     QWORD PTR [RBP - 16], RCX
        mov     EDX, 2
        call    RAX
        mov     RCX, QWORD PTR [RBP - 32]
        mov     QWORD PTR [RBX], RCX
        add     RSP, 40
        pop     RBX
        pop     RBP
        ret

julia> @code_native b()
        .text
Filename: none
Source line: 1
        push    RBP
        mov     RBP, RSP
        mov     EAX, 173166928
Source line: 1
        pop     RBP
        ret

Note that @code_native f() = A is just as short as for b.

@JeffBezanson JeffBezanson added the compiler:codegen Generation of LLVM IR and native code label Sep 24, 2015
@carnaval
Copy link
Contributor

I think it's just about weakening

isleaftype(e.typ.parameters[1])

this should not need a leaftype, just something that is not a typevar should be ok

@JeffBezanson
Copy link
Member

+1 to that

@mauro3
Copy link
Contributor Author

mauro3 commented Sep 28, 2015

Thanks for looking into this. I hope fixing this will make trait methods in Traits.jl just as efficient as normal methods. At the moment, they usually produce more native code.

bjarthur pushed a commit to bjarthur/julia that referenced this issue Oct 27, 2015
@tkelman
Copy link
Contributor

tkelman commented Oct 31, 2015

@JeffBezanson backport this or no?

@JeffBezanson
Copy link
Member

Yes should be safe.

@tkelman
Copy link
Contributor

tkelman commented Oct 31, 2015

thanks, though there are some nasty conflicts so I think I'll skip this for now? it might depend on a verdict on #13491 and #13553 edit: depends on #13434 so will leave off for now.

@JeffBezanson
Copy link
Member

This is not crucial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

No branches or pull requests

4 participants