google / bloaty

Bloaty: a size profiler for binaries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Function size includes its name

antelle opened this issue · comments

Hi!
This seems to be an awesome tool, however I discovered that the function size reported by bloaty actually includes its name. Here's how I tested it:
Here's my example, main.cpp:

int short_name() { return 2; }
int long_name_12345678901234567890123456789012345678901234567890() { return 3; }
int longer_name_1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890() { return 4; }

int main() {
    short_name();
    long_name_12345678901234567890123456789012345678901234567890();
    longer_name_1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890();
}

Compile it:

em++ main.cpp -o main.js -g2 -O0

Run bloaty:

bloaty -d symbols --domain=file main.wasm | grep name
   1.3%     128    longer_name_1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890()
   0.8%      76    long_name_12345678901234567890123456789012345678901234567890()
   0.3%      26    short_name()

Compare with wasm-objdump:

wasm-objdump -x main.wasm | grep "size.*name"
 - func[4] size=11 <short_name()>
 - func[5] size=11 <long_name_12345678901234567890123456789012345678901234567890()>
 - func[6] size=11 <longer_name_1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890()>

The same applies to native code.
This behavior can be desired in some cases though. Is it possible to add an argument that would exclude function name size?

Yes, what you are seeing is intentional. The function's name takes up space in the binary, and Bloaty looks for all the places in the binary where a function takes up space.

If we didn't do this, the individual numbers wouldn't add up to the full size of the file on disk.

If you want to separate out the different parts of each symbol, I would recommend:

$ bloaty -d sections,symbols --domain=file main.wasm

Thanks for the advice! I didn't realize that -d sections,symbols can actually split code and name this way because they're indeed in different sections.