Skip to content

Add flags for size optimization#9547

Merged
bhavya01 merged 1 commit intor2.8from
size_opt
Aug 7, 2025
Merged

Add flags for size optimization#9547
bhavya01 merged 1 commit intor2.8from
size_opt

Conversation

@bhavya01
Copy link
Copy Markdown
Collaborator

@bhavya01 bhavya01 commented Aug 7, 2025

https://bazel.build/docs/user-manual#build-semantics shows that bazel build -c opt is the same as bazel build --copt="-O2" --copt="-DNDEBUG"

Instead, we optimize for size by using bazel build --copt="-Os". This uses most of -O2 optimization except the ones list here:

-falign-functions  -falign-jumps
-falign-labels  -falign-loops
-fprefetch-loop-arrays  -freorder-blocks-algorithm=stc

Out of these -fprefetch-loop-arrays doesn't work with -Os. All others work without increasing the wheel size. The final wheel size after this change is 84MB.

Reference: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

@bhavya01 bhavya01 requested a review from zhanyong-wan August 7, 2025 21:22
Copy link
Copy Markdown
Collaborator

@zhanyong-wan zhanyong-wan left a comment

Choose a reason for hiding this comment

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

Thanks!

@bhavya01 bhavya01 merged commit ad76b20 into r2.8 Aug 7, 2025
23 of 24 checks passed
jeffhataws pushed a commit that referenced this pull request Sep 2, 2025
#9605

**key Change**

- This reverts commit ad76b20. (#9547)

Co-authored-by: Raj Thakur <rjtha@amazon.com>
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