Skip to content

Replace the splitManifests regex#13441

Closed
borissmidt wants to merge 1 commit into
helm:mainfrom
borissmidt:fasterSplitManifests
Closed

Replace the splitManifests regex#13441
borissmidt wants to merge 1 commit into
helm:mainfrom
borissmidt:fasterSplitManifests

Conversation

@borissmidt

@borissmidt borissmidt commented Nov 12, 2024

Copy link
Copy Markdown

What this PR does / why we need it:
The regex is slow, we use helm in a gitops repo and template a lot of helm in our CI steps and it is getting quite slow because i've profiled helm itself and found true bottlenecks:

  1. Splitting the yaml output (this part)
  2. Sorting the yaml output because it has to parse the source
  3. Reading the chart index in the chart downloader

Special notes for your reviewer:

If applicable:

  • this PR contains user facing changes (the docs needed label should be applied if so)
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

@pull-request-size pull-request-size Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 12, 2024
@mattfarina

Copy link
Copy Markdown
Collaborator

Reading the chart index in the chart downloader

FYI, you can get a massive performance boost by using JSON in the index.yaml. A JSON document is valid YAML. More recent versions of Helm detect JSON and use a JSON parser. JSON parsers are faster and use fewer resources. YAML is more difficult to parse due to things like anchors.

Comment thread pkg/releaseutil/manifest.go Outdated
@@ -49,13 +50,99 @@ spec:
image: fake-image
cmd: fake-command`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd think there would be more test cases

Comment thread pkg/releaseutil/manifest.go Outdated
// i = 3
//}

for i < len(bigFile) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If I was writing this, I'd be tempted to look at creating a scanner and/or state machine to make this more readable. I think something could be done that wouldn't hurt performance.

@borissmidt borissmidt Nov 16, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Today i tried two implementations, one with a 'scanner/iterator' but this was clearer to read.

But then looking at the profiler output i saw that 'strings.Prefix' is highly optimized so i tried a 'naive' implementation which was actually twice as fast.

It now checks at very subslice that it start with "\n---".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is a lot easier to read now, thanks!

@borissmidt

borissmidt commented Nov 15, 2024 via email

Copy link
Copy Markdown
Author

@borissmidt

Copy link
Copy Markdown
Author

I've made an updated implementation which is simpler and more maintainable.

@TerryHowe

Copy link
Copy Markdown
Contributor

You'll probably get more eyes on this if the DCO was fixed https://github.com/helm/helm/pull/13441/checks?check_run_id=33081873991

Signed-off-by: boris smidt <smidtboris1@gmail.com>
@borissmidt

Copy link
Copy Markdown
Author

@TerryHowe thank you i've added the singing which fixes the DCO, I also rebased on master and improved the commti message. So i hope it is ready now for review.

@borissmidt

Copy link
Copy Markdown
Author

Is there anything holding us back here?

@borissmidt borissmidt closed this Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants