Skip to content

Conversation

@mnapoli
Copy link
Member

@mnapoli mnapoli commented May 26, 2025

The goal is to reduce layer sizes to optimize cold starts (that's the theory at least).

  • strip debug symbols for all libraries and PHP extensions (saves 11.7%)
  • compile PHP with the -Os C/CPP flag to optimize the binary for size (saves 8%)
  • compile libraries with the -Os flag (saves 6.3%)
  • disable the soap extension by default to avoid loading it on PHP startup (the only big unpopular extension I could find)
  • bundle the pdo-mysql extension in the PHP binary: it is extra small and will avoid loading it through an external file (small optimization)

In total that's a 24% size reduction, i.e. 14.6MB.

This is for Bref v3, I will run some benchmarks as just measuring the layer size doesn't tell us the full story about cold starts.

The goal is to reduce layer sizes to optimize cold starts (that's the theory at least).

- `strip` debug symbols for all libraries and PHP extensions (saves 11.7%)
- compile PHP with the `-Os` C/CPP flag to optimize the binary for size (saves 8%)
- compile libraries with the `-Os` flag (saves 6.3%)
- disable the `soap` extension by default to avoid loading it on PHP startup (the only big unpopular extension I could find)
- bundle the `pdo-mysql` extension in the PHP binary: it is extra small and will avoid loading it through an external file (small optimization)

In total that's a 24% size reduction, i.e. 14.6MB.

This is for Bref v3, I will run some benchmarks as just measuring the layer size doesn't tell us the full story about cold starts.
@mnapoli mnapoli mentioned this pull request May 26, 2025
3 tasks
@GrahamCampbell
Copy link
Contributor

compile PHP with the -Os C/CPP flag to optimize the binary for size (saves 8%)

This could probably be backported to bref 2 without any issues.

@mnapoli
Copy link
Member Author

mnapoli commented May 26, 2025

Yes but there is some uncertainty on whether -Os is worth it over -O3 or even -O2 in terms of performance, so I'd feel much more comfortable being able to have a long beta period where multiple people can beta test these changes.

@GrahamCampbell
Copy link
Contributor

GrahamCampbell commented May 26, 2025

Ah, good point. -O1 or even -O2 are probably quite conservative options to go with in Bref 2, if we wanted.

@GrahamCampbell
Copy link
Contributor

Asking Claude what it thinks...

image

@mnapoli
Copy link
Member Author

mnapoli commented May 26, 2025

I'll run some benchmarks and see if there is any noticeable change

@mnapoli mnapoli merged commit 2c97d8d into v3 May 26, 2025
7 checks passed
@mnapoli mnapoli deleted the optimize-layers branch May 26, 2025 18:25
@mnapoli mnapoli mentioned this pull request May 27, 2025
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.

3 participants