Skip to content

Outline buffer functions #20856

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Outline buffer functions #20856

wants to merge 1 commit into from

Conversation

vkalintiris
Copy link
Contributor

@vkalintiris vkalintiris commented Aug 20, 2025

Inlining everything bloats our binary size. Outlining just the buffer functions reduces binary size by half.

Before this change:

FILE SIZE        VM SIZE
 --------------  --------------
  75.0%  9.92Mi  70.8%  9.92Mi    .text
   0.0%       0   5.6%   802Ki    .bss
   4.8%   656Ki   4.6%   656Ki    .eh_frame
   4.1%   553Ki   3.9%   552Ki    .data
   3.9%   525Ki   3.7%   525Ki    .dynstr
   3.7%   494Ki   3.4%   494Ki    .rodata.str1.1
   1.8%   240Ki   1.7%   240Ki    .dynsym
   1.7%   233Ki   1.6%   233Ki    .rela.dyn
   1.2%   159Ki   1.1%   159Ki    .rodata
   1.0%   131Ki   0.9%   131Ki    .gcc_except_table
   0.9%   126Ki   0.9%   126Ki    .eh_frame_hdr
   0.6%  77.9Ki   0.5%  74.5Ki    .data.rel.ro
   0.4%  58.3Ki   0.4%  58.2Ki    .gnu.hash
   0.3%  40.0Ki   0.3%  39.9Ki    .rodata.str1.8
   0.2%  22.8Ki   0.2%  22.8Ki    protodesc_cold
   0.1%  20.1Ki   0.1%  20.0Ki    .gnu.version
   0.1%  11.2Ki   0.1%  14.9Ki    [30 Others]
   0.1%  14.6Ki   0.1%  14.5Ki    .rela.plt
   0.1%  9.78Ki   0.1%  9.72Ki    .plt
   0.0%  4.93Ki   0.0%  4.87Ki    .got.plt
   0.0%  4.00Ki   0.0%  3.94Ki    .tdata
 100.0%  13.2Mi 100.0%  14.0Mi    TOTAL

After:

FILE SIZE        VM SIZE
 --------------  --------------
  60.3%  4.86Mi  55.0%  4.86Mi    .text
   0.0%       0   8.9%   802Ki    .bss
   7.8%   641Ki   7.1%   641Ki    .eh_frame
   6.7%   553Ki   6.1%   552Ki    .data
   6.4%   527Ki   5.8%   527Ki    .dynstr
   6.0%   494Ki   5.5%   494Ki    .rodata.str1.1
   2.9%   242Ki   2.7%   242Ki    .dynsym
   2.8%   233Ki   2.6%   233Ki    .rela.dyn
   1.5%   127Ki   1.4%   127Ki    .eh_frame_hdr
   1.4%   115Ki   1.3%   115Ki    .gcc_except_table
   0.9%  77.8Ki   0.8%  74.5Ki    .data.rel.ro
   0.9%  71.7Ki   0.8%  71.7Ki    .rodata
   0.7%  58.6Ki   0.6%  58.6Ki    .gnu.hash
   0.5%  40.0Ki   0.4%  39.9Ki    .rodata.str1.8
   0.3%  22.8Ki   0.3%  22.8Ki    protodesc_cold
   0.2%  20.3Ki   0.2%  20.2Ki    .gnu.version
   0.2%  14.6Ki   0.2%  14.5Ki    .rela.plt
   0.1%  11.3Ki   0.1%  13.1Ki    [30 Others]
   0.1%  9.78Ki   0.1%  9.72Ki    .plt
   0.1%  4.93Ki   0.1%  4.87Ki    .got.plt
   0.0%  4.00Ki   0.0%  3.94Ki    .tdata
 100.0%  8.05Mi 100.0%  8.83Mi    TOTAL

Inlining everything bloats our binary size. Outlining just the buffer
functions reduces binary size by half.

Before this change:

FILE SIZE        VM SIZE
 --------------  --------------
  75.0%  9.92Mi  70.8%  9.92Mi    .text
   0.0%       0   5.6%   802Ki    .bss
   4.8%   656Ki   4.6%   656Ki    .eh_frame
   4.1%   553Ki   3.9%   552Ki    .data
   3.9%   525Ki   3.7%   525Ki    .dynstr
   3.7%   494Ki   3.4%   494Ki    .rodata.str1.1
   1.8%   240Ki   1.7%   240Ki    .dynsym
   1.7%   233Ki   1.6%   233Ki    .rela.dyn
   1.2%   159Ki   1.1%   159Ki    .rodata
   1.0%   131Ki   0.9%   131Ki    .gcc_except_table
   0.9%   126Ki   0.9%   126Ki    .eh_frame_hdr
   0.6%  77.9Ki   0.5%  74.5Ki    .data.rel.ro
   0.4%  58.3Ki   0.4%  58.2Ki    .gnu.hash
   0.3%  40.0Ki   0.3%  39.9Ki    .rodata.str1.8
   0.2%  22.8Ki   0.2%  22.8Ki    protodesc_cold
   0.1%  20.1Ki   0.1%  20.0Ki    .gnu.version
   0.1%  11.2Ki   0.1%  14.9Ki    [30 Others]
   0.1%  14.6Ki   0.1%  14.5Ki    .rela.plt
   0.1%  9.78Ki   0.1%  9.72Ki    .plt
   0.0%  4.93Ki   0.0%  4.87Ki    .got.plt
   0.0%  4.00Ki   0.0%  3.94Ki    .tdata
 100.0%  13.2Mi 100.0%  14.0Mi    TOTAL

After:

FILE SIZE        VM SIZE
 --------------  --------------
  60.3%  4.86Mi  55.0%  4.86Mi    .text
   0.0%       0   8.9%   802Ki    .bss
   7.8%   641Ki   7.1%   641Ki    .eh_frame
   6.7%   553Ki   6.1%   552Ki    .data
   6.4%   527Ki   5.8%   527Ki    .dynstr
   6.0%   494Ki   5.5%   494Ki    .rodata.str1.1
   2.9%   242Ki   2.7%   242Ki    .dynsym
   2.8%   233Ki   2.6%   233Ki    .rela.dyn
   1.5%   127Ki   1.4%   127Ki    .eh_frame_hdr
   1.4%   115Ki   1.3%   115Ki    .gcc_except_table
   0.9%  77.8Ki   0.8%  74.5Ki    .data.rel.ro
   0.9%  71.7Ki   0.8%  71.7Ki    .rodata
   0.7%  58.6Ki   0.6%  58.6Ki    .gnu.hash
   0.5%  40.0Ki   0.4%  39.9Ki    .rodata.str1.8
   0.3%  22.8Ki   0.3%  22.8Ki    protodesc_cold
   0.2%  20.3Ki   0.2%  20.2Ki    .gnu.version
   0.2%  14.6Ki   0.2%  14.5Ki    .rela.plt
   0.1%  11.3Ki   0.1%  13.1Ki    [30 Others]
   0.1%  9.78Ki   0.1%  9.72Ki    .plt
   0.1%  4.93Ki   0.1%  4.87Ki    .got.plt
   0.0%  4.00Ki   0.0%  3.94Ki    .tdata
 100.0%  8.05Mi 100.0%  8.83Mi    TOTAL
@vkalintiris vkalintiris self-assigned this Aug 20, 2025
@vkalintiris
Copy link
Contributor Author

@ktsaou If you want to inline a function do so after measuring the performance difference. Inlining everything defeats the purpose because you'll end up trashing the instruction cache.

@vkalintiris vkalintiris requested a review from ktsaou August 20, 2025 06:06
*e = '\0';
return e - dst;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor, I have observed some additional unnecessary space between functions.

Copy link
Contributor

@thiagoftsm thiagoftsm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is working as expected. LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants