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

bundle: Load bundle once #1136

Merged
merged 2 commits into from
Sep 25, 2024
Merged

Conversation

charlieegan3
Copy link
Member

@charlieegan3 charlieegan3 commented Sep 25, 2024

Previously, loading of the bundle happened many times, each time it takes around 20ms. This improves the performance of the language server by loading the bundle once and reusing it since the bundle is never changed once a binary is running.

before

Screen.Recording.2024-09-25.at.10.19.12.mov

after

Screen.Recording.2024-09-25.at.10.20.29.mov

@@ -102,8 +100,8 @@ func (l Linter) WithInputModules(input *rules.Input) Linter {
}

// WithAddedBundle adds a bundle of rules and data to include in evaluation.
func (l Linter) WithAddedBundle(b bundle.Bundle) Linter {
l.ruleBundles = append(l.ruleBundles, &b)
func (l Linter) WithAddedBundle(b *bundle.Bundle) Linter {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an API change. We can do it without this, but it feels right to do it given how this function is used.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not used in the Rego playground or in any public code on https://sourcegraph.com/search?q=context:global+WithAddedBundle&patternType=keyword&sm=0

bundle/bundle.go Outdated
loadedBundleOnce sync.Once
)

// LoadedBundle returns the loaded Regal bundle for this version of Regal.
Copy link
Member

Choose a reason for hiding this comment

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

I take it you'd like to keep it being lazily loaded? Because if it was going to be used anyways, often times sync.Once etc can be replaced with a package var, like

var loadedBundle = io.MustLoadRegalBundleFS(Bundle)

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps we should just do this 👍 I was remembering a discussion about how inits in the ls implementation were slowing down the linting cmd, but that's not the case here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 9c2e409

Previously, loading of the bundle happened many times, each time it
takes around 20ms. This improves the performance of the language server
by loading the bundle once and reusing it since the bundle is never
changed once a binary is running.

Signed-off-by: Charlie Egan <charlie@styra.com>
Follows PR review comment

Signed-off-by: Charlie Egan <charlie@styra.com>
@charlieegan3
Copy link
Member Author

Thanks Stephan!

@charlieegan3 charlieegan3 merged commit 6ecb36c into StyraInc:main Sep 25, 2024
4 checks passed
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
* bundle: Load bundle once

Previously, loading of the bundle happened many times, each time it
takes around 20ms. This improves the performance of the language server
by loading the bundle once and reusing it since the bundle is never
changed once a binary is running.

Signed-off-by: Charlie Egan <charlie@styra.com>

* bundle: use pkg var

Follows PR review comment

Signed-off-by: Charlie Egan <charlie@styra.com>

---------

Signed-off-by: Charlie Egan <charlie@styra.com>
charlieegan3 added a commit to charlieegan3/regal that referenced this pull request Jan 6, 2025
* bundle: Load bundle once

Previously, loading of the bundle happened many times, each time it
takes around 20ms. This improves the performance of the language server
by loading the bundle once and reusing it since the bundle is never
changed once a binary is running.

Signed-off-by: Charlie Egan <charlie@styra.com>

* bundle: use pkg var

Follows PR review comment

Signed-off-by: Charlie Egan <charlie@styra.com>

---------

Signed-off-by: Charlie Egan <charlie@styra.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