Skip to content

⚡ Optimize toProjectName regex compilation - #1201

Closed
skevetter wants to merge 3 commits into
mainfrom
perf/optimize-compose-project-name-regex-17227207174072885957
Closed

⚡ Optimize toProjectName regex compilation#1201
skevetter wants to merge 3 commits into
mainfrom
perf/optimize-compose-project-name-regex-17227207174072885957

Conversation

@skevetter

@skevetter skevetter commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

💡 What: Extracted the literal regex regexp.MustCompile calls in pkg/compose/helper.go:toProjectName into package-level variables (oldProjectNameRegex and newProjectNameRegex).

🎯 Why: Previously, the regexp.MustCompile("[^a-z0-9]") and regexp.MustCompile("[^-_a-z0-9]") expressions were compiled on every invocation of toProjectName. Regex compilation is computationally expensive. By lifting them to package-level variables, they are only compiled once when the package is initialized, significantly reducing unnecessary CPU cycles and memory allocations per function call.

📊 Measured Improvement:
A benchmark was added in pkg/compose/helper_bench_test.go to measure the difference before and after the optimization.

Baseline (Before Optimization):

BenchmarkToProjectName-4             	  106602	     10105 ns/op
BenchmarkToProjectName_NewFormat-4   	  115938	     10966 ns/op

Optimized (After Extraction):

BenchmarkToProjectName-4             	  185187	      5871 ns/op
BenchmarkToProjectName_NewFormat-4   	  181635	      6484 ns/op

Results: The operation time was reduced from ~10,105 ns/op to ~5,871 ns/op (a ~41% improvement) for the old format, and from ~10,966 ns/op to ~6,484 ns/op (a ~40% improvement) for the new format.


PR created automatically by Jules for task 17227207174072885957 started by @skevetter

Summary by CodeRabbit

  • Performance
    • Improved project-name processing efficiency without changing sanitization behavior across supported Compose versions.
  • Tests
    • Added benchmark coverage for legacy and current Compose version formats.

Extracted the `regexp.MustCompile` calls in `toProjectName` into package-level variables so they are compiled only once during initialization rather than on every invocation.
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@netlify

netlify Bot commented Sep 7, 2026

Copy link
Copy Markdown

Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit 2bd9ea5
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6a9f37243fad2f0008533ad9

@netlify

netlify Bot commented Sep 7, 2026

Copy link
Copy Markdown

Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit 2bd9ea5
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6a9f3724431ae900086cfd59

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 6404457c-e294-4a41-9d77-4ccb2382e66f

📥 Commits

Reviewing files that changed from the base of the PR and between 9ac2107 and afdef91.

📒 Files selected for processing (2)
  • pkg/compose/helper.go
  • pkg/compose/helper_bench_test.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

toProjectName now reuses package-level regular expressions for project-name sanitization. The existing legacy and current Compose naming behavior remains unchanged. Benchmarks cover both version formats.

Changes

Compose project-name optimization

Layer / File(s) Summary
Sanitization reuse and benchmark coverage
pkg/compose/helper.go, pkg/compose/helper_bench_test.go
toProjectName reuses compiled regular expressions for legacy and current Compose formats. Benchmarks repeatedly test both formats.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 2bd9e

Compose project-name sanitization now avoids recompiling its regular expressions on each call while retaining the existing legacy and current naming paths. No merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: optimizing regex compilation in toProjectName.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch perf/optimize-compose-project-name-regex-17227207174072885957

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

⚠️ This PR contains unsigned commits. To get your PR merged, please sign those commits (git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch (git push --force-with-lease).

If you're new to commit signing, there are different ways to set it up:

Sign commits with gpg

Follow the steps below to set up commit signing with gpg:

  1. Generate a GPG key
  2. Add the GPG key to your GitHub account
  3. Configure git to use your GPG key for commit signing
Sign commits with ssh-agent

Follow the steps below to set up commit signing with ssh-agent:

  1. Generate an SSH key and add it to ssh-agent
  2. Add the SSH key to your GitHub account
  3. Configure git to use your SSH key for commit signing
Sign commits with 1Password

You can also sign commits using 1Password, which lets you sign commits with biometrics without the signing key leaving the local 1Password process.

Learn how to use 1Password to sign your commits.

Watch the demo

@github-actions github-actions Bot added the size/s label Sep 7, 2026
Extracted the regexp.MustCompile calls in toProjectName into package-level variables so they are compiled only once during initialization rather than on every invocation.
Extracted the regexp.MustCompile calls in toProjectName into package-level variables so they are compiled only once during initialization rather than on every invocation.
@skevetter skevetter closed this Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant