Skip to content

feat(comp): Speed up completion of charts - #6809

Merged
marckhouzam merged 1 commit into
helm:masterfrom
VilledeMontreal:feat/compUseCache
Jan 15, 2020
Merged

marckhouzam merged 1 commit into
helm:masterfrom
VilledeMontreal:feat/compUseCache

Conversation

@marckhouzam

@marckhouzam marckhouzam commented Oct 29, 2019 •

Copy link
Copy Markdown
Member

I feel that this improvement in performance when listing charts makes it much more useful to use shell completion when wanting to find a chart.

The completion of charts was using helm search repo which can be quite slow as it must parse the entire yaml of every repo cache file.

EDIT: please see #6809 (comment) below for a description of the reworked PR.

This commit makes the completion logic access the correct repo cache file directly and only extract the chart names from it.

With only the stable repo configured, this optimization makes the completion of charts about 10 times faster, going from 1.1 seconds (which is quite slow for a user doing completion) to 0.14 seconds; such a difference give a much better user experience.

If other repos are configured, helm search repo only become slower, while the new completion logic will not be affected as it only looks for the relevant single repo file.

Notes for maintainers:

Can a maintainer tell me their opinion on the approach of using the cache file by:
1- extracting the cache directory by looking for HELM_REPOSITORY_CACHE in the output of helm env
2- greping for chart names (using \egrep -e '^ [a-zA-Z]' on the $repo-index.yaml cache file

I would have liked something a little more straightforward, but nothing better jumped out at me.

This change was tested for backwards-compatibility using the acceptance-testing repo

@helm-bot helm-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 29, 2019
@thomastaylor312 thomastaylor312 added v3.x Issues and Pull Requests related to the major version v3 refactor labels Oct 30, 2019
@thomastaylor312 thomastaylor312 added this to the 3.1.0 milestone Oct 30, 2019
@marckhouzam

Copy link
Copy Markdown
Member Author

Although technically not a bug fix, this is only a 2-line change that makes the completion of charts much nicer. The change is safe as it can only affect completion.

I wonder if this could be considered for the 3.0 release?

The user experience would be much nicer because, when completing the name of a chart, (e.g. helm install myrelease stable/ngi<TAB> a user may press <TAB> multiple times; without this fix, each <TAB> will take around 2 seconds or more, which defeats the purpose of asking the computer to complete the word faster than if the user had typed it.

@helm-bot helm-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 3, 2019
@marckhouzam

marckhouzam commented Dec 3, 2019 •

Copy link
Copy Markdown
Member Author

I reworked this PR in a much less hacky fashion.

This new attempt has helm create a new cache file for each repo which contains the list of charts for that repo. Helm will do this whenever it downloads the repo index file.

The completion logic then uses this new cache file directly and obtains the chart names very quickly.
With only the stable repo configured, this optimization makes the completion of charts about 85 times faster, going from 1.2 seconds to 0.014 seconds; such a difference gives a much better user experience when completing chart names (e.g., helm install nginx stable/ng<TAB>).

On the other hand, adding the creation of the new chart-list cache file to helm update or helm add is pretty much negligible compared to the time spent parsing the index files.

@marckhouzam

Copy link
Copy Markdown
Member Author

I've just added tests for this change and also fixed the fact that I had forgotten to remove the new cache file when doing a helm repo remove

@bacongobbler bacongobbler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! I would suggest adding more test coverage for some of the new added functionality, but overall this looks like it solves the issue

Comment thread pkg/repo/chartrepo.go
// Create the chart list file in the cache directory
var charts strings.Builder
for name := range indexFile.Entries {
fmt.Fprintln(&charts, name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would you mind writing a unit test for this if possible?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will do. Thanks for the review!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The simplest way to test this was to extend the Index file test of index_test.go.
The latest version of the PR does just that.

@marckhouzam

Copy link
Copy Markdown
Member Author

This last forced push was just to rebase and to correct the commit message. New tests still pending.

The completion of charts was using 'helm search repo' which can be
quite slow as it must parse the entire yaml of every repo cache file.
Using completion for a chart name can end up triggering multiple calls
to 'helm search'; this makes the user experience poor, as there is
a delay of over a second at every <TAB> press.

This commit creates a cache file for each repo which contains the list
of charts for that repo.  The completion logic then uses this new
cache file directly and obtains the chart names very quickly.

With only the stable repo configured, this optimization makes the
completion of charts about 85 times faster, going from 1.2 seconds to
0.014 seconds; such a difference gives a much better user experience
when completing chart names.

On the other hand, adding the creation of the chart list cache file to
'helm repo update' or 'helm repo add' is pretty much negligible compared
to the downloading of the index file.

It is also worth noting that when more repos are configured,
'helm search repo' only becomes slower, while the completion logic that
uses the new chart list cache file will not be affected as it only looks
for the single relevant repo file.

Signed-off-by: Marc Khouzam <[email protected]>
@helm-bot helm-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 12, 2020
@marckhouzam

Copy link
Copy Markdown
Member Author

@bacongobbler ready for review again.

@bacongobbler bacongobbler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

manually tested. LGTM!

@marckhouzam
marckhouzam merged commit 1a13366 into helm:master Jan 15, 2020
@marckhouzam
marckhouzam deleted the feat/compUseCache branch January 15, 2020 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor size/L Denotes a PR that changes 100-499 lines, ignoring generated files. v3.x Issues and Pull Requests related to the major version v3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants