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

perf: optimize activation of bundles with no inter-bundle path overlap #7155

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

sqyang94
Copy link

@sqyang94 sqyang94 commented Nov 4, 2024

Why the changes in this PR are needed?

When multiple bundles are loaded into OPA using the bundle plugin, it takes a long time to active the bundles according to the logs. Profiling results has shown that most of the activation time is spent in checking path conflicts.

This PR avoids unnecessary path conflict checking when no root overlaps are guaranteed. This will reduce the number of expensive deep copies and hence improve bundle activation time and CPU utilization.

Resolves #7144.

What are the changes in this PR?

If a bundle has a manifest file with roots defined, then during path conflict checking, only check the sub-AST from the root path instead of the entire AST.

Notes to assist PR review:

#7144 includes a detailed explanation and context on this change.

Further comments:

I wasn't able to find a good way of directly testing the change (i.e. testing that only subtree was checked when roots are defined in the manifest). Instead, I added some bundle plugin tests with different scenarios to make sure conflicts are correctly checked still.

Ideas on how to directly test this approach are welcome :)

ast/compile.go Outdated
// WithPathConflictsCheckRoot enables checking path conflicts from the specified root instead
// of the top root node. This would enable optimizting path conflict checks during bundle
// activation if a bundle already defines its own root paths.
func (c *Compiler) WithPathConflictsCheckRoot(rootPaths []string) *Compiler {
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to use singular "root" for the name while the args and the property says "roots"?

Copy link
Author

Choose a reason for hiding this comment

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

Good catch! Will change to use the plural form.

@sqyang94 sqyang94 force-pushed the check-conflict-from-child-node branch from 179ecc8 to 5cd286b Compare November 4, 2024 18:54
@sqyang94
Copy link
Author

sqyang94 commented Nov 4, 2024

Force pushing to sign off my commits...

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.

Optimize activation of bundles with no inter-bundle path overlap
4 participants