Skip to content
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

fix: shave some size off the executable #68

Merged
merged 1 commit into from
Oct 5, 2024
Merged

fix: shave some size off the executable #68

merged 1 commit into from
Oct 5, 2024

Conversation

jamestelfer
Copy link
Owner

@jamestelfer jamestelfer commented Oct 5, 2024

Trim symbol paths and remove DWARF debugging symbols from the built binaries. These slow compilation and increase binary size.

If debugging information is necessary, a different build target could be used.

The binary size metric is not driving this change, but more of a nice-to-have. Trimming module paths removes irrelevant information from any traces that are emitted, and speeding the build time helps development cycle time.

Summary by CodeRabbit

  • New Features
    • Enhanced build process with new flags for optimized builds.
    • Introduced a distribution directory for better organization of output binaries.
  • Bug Fixes
    • Improved handling of Go modules and test coverage reporting.
  • Documentation
    • Updated instructions for release verification and Docker image tagging.

Trim symbol paths and remove DWARF debugging symbols from the built binaries. These slow compilation and increase binary size.

If debugging information is necessary, a different build target could be used.
Copy link

coderabbitai bot commented Oct 5, 2024

Walkthrough

The pull request introduces modifications to the .goreleaser.yaml and Makefile files. In .goreleaser.yaml, new flags for the release build configuration are added, affecting the build process. The Makefile updates include new targets for managing Go modules, running tests, and creating distribution directories, along with changes to the build commands to optimize output. The overall changes enhance the build and release process, particularly focusing on Docker image handling and artifact signing.

Changes

File Changes Summary
.goreleaser.yaml - Added flags: "-trimpath" and ldflags: "-w" to builds section for release.
- Updated sections for signing artifacts, checksum generation, changelog configuration, release metadata, and Docker image handling.
Makefile - Introduced dist target for creating a distribution directory.
- Updated build target to include -ldflags="-w" -trimpath.
- Modified test, test-ci, run, docker, docker-down, and ensure-deps targets.
- Added keygen target for generating JWKS key pair.

Possibly related PRs

  • feat: sign released binaries and images with cosign #60: The changes in .goreleaser.yaml related to signing artifacts with cosign are directly connected to the modifications made in the main PR, which also involve updates to the .goreleaser.yaml file for build configurations and signing processes.
  • ci: fix errors in release process #61: The updates to the binary_signs section in .goreleaser.yaml to include a signature key are relevant to the changes in the main PR, which also modifies the .goreleaser.yaml file and addresses the signing process for artifacts.

Poem

In the meadow where code does play,
New flags and targets brighten the day.
With builds that trim and signs that gleam,
Our project grows, a coder's dream!
So hop along, let the changes flow,
For in this world, together we grow! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Oct 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.40%. Comparing base (a0fd6da) to head (487a3d0).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #68   +/-   ##
=======================================
  Coverage   90.40%   90.40%           
=======================================
  Files          13       13           
  Lines         521      521           
=======================================
  Hits          471      471           
  Misses         34       34           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
Makefile (1)

27-27: Consider adding a debug build target

The optimization for the local build is consistent with the container build, which is great for maintaining parity. However, stripping debug information might hinder local debugging.

Suggestion: Consider adding a separate debug build target that retains debugging information for local development use.

Example of a debug build target:

.PHONY: build-debug
build-debug: dist mod
	CGO_ENABLED=0 go build -o dist/chinmina-bridge-debug .

This allows developers to choose between optimized and debug builds as needed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a0fd6da and 487a3d0.

📒 Files selected for processing (2)
  • .goreleaser.yaml (1 hunks)
  • Makefile (1 hunks)
🔇 Additional comments (2)
Makefile (1)

25-25: Excellent optimization for container build!

The addition of -ldflags="-w" -trimpath flags is a great improvement:

  1. -w strips DWARF debugging information, reducing binary size.
  2. -trimpath removes file system paths, enhancing security by eliminating potentially sensitive information.

These changes align perfectly with the PR objectives of reducing binary size and trimming symbol paths.

.goreleaser.yaml (1)

13-14: Approve changes with considerations for debugging

The addition of flags: "-trimpath" and ldflags: "-w" aligns well with the PR objectives:

  1. -trimpath removes file system paths from the binary, which can slightly reduce size and improve build reproducibility.
  2. -w omits the DWARF symbol table, significantly reducing binary size.

These changes will effectively reduce the size of the built binaries as intended. However, they come with trade-offs:

  • Debugging in production environments will be more challenging.
  • Stack traces will have less information, potentially making issue diagnosis more difficult.

To ensure these changes don't negatively impact the project's debugging capabilities, please run the following script:

If any of these searches return results, we may need to reconsider the impact of these changes or provide alternative debugging solutions.

@jamestelfer jamestelfer merged commit 7b64842 into main Oct 5, 2024
6 checks passed
@jamestelfer jamestelfer deleted the binary-diet branch October 5, 2024 14:29
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.

1 participant