h3 icon indicating copy to clipboard operation
h3 copied to clipboard

No inlining in library

Open Komzpa opened this issue 5 years ago • 2 comments

Hello,

I'm fighting https://github.com/bytesandbrains/h3-pg/issues/23. Embarrassingly simple invocations aren't getting inlined:

objdump -D ./benchmarkH3Api image

This also looks quite bad in flamegraph: image

Komzpa avatar Mar 26 '20 08:03 Komzpa

Could these automatically get inlined if H3 were built as a static library instead of a shared library? (CMake option -DBUILD_SHARED_LIBS=OFF) When I compile the benchmarks with static H3 and release build, I get the following code (from objdump -D benchmarkKRing):

000000000000eec0 <_pointSquareDist>:
    eec0:       f2 0f 10 0f             movsd  (%rdi),%xmm1
    eec4:       f2 0f 10 47 08          movsd  0x8(%rdi),%xmm0
    eec9:       f2 0f 5c 0e             subsd  (%rsi),%xmm1
    eecd:       f2 0f 10 57 10          movsd  0x10(%rdi),%xmm2
    eed2:       f2 0f 5c 46 08          subsd  0x8(%rsi),%xmm0
    eed7:       f2 0f 5c 56 10          subsd  0x10(%rsi),%xmm2
    eedc:       f2 0f 59 c9             mulsd  %xmm1,%xmm1
    eee0:       f2 0f 59 c0             mulsd  %xmm0,%xmm0
    eee4:       f2 0f 59 d2             mulsd  %xmm2,%xmm2
    eee8:       f2 0f 58 c8             addsd  %xmm0,%xmm1
    eeec:       f2 0f 58 ca             addsd  %xmm2,%xmm1
    eef0:       66 0f 28 c1             movapd %xmm1,%xmm0
    eef4:       c3                      retq   
    eef5:       90                      nop
    eef6:       66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
    eefd:       00 00 00

Edit: The code for this function wouldn't be present if the library isn't built statically, I think the difference here is the use of -DCMAKE_BUILD_TYPE=Release.

isaacbrodsky avatar Mar 26 '20 23:03 isaacbrodsky

Here's how it's built for the final postgres module. https://github.com/bytesandbrains/h3-pg/blob/master/Makefile#L80

I tried adding -DCMAKE_BUILD_TYPE=Release there but somehow still get functions not inlined in my final build of h3-pg.

Komzpa avatar Mar 27 '20 09:03 Komzpa