Skip to content

Conversation

@anderseknert
Copy link
Member

Parsing is generally fast, so this mainly improves performance of creating big bundles with many Rego files in them. For Regal's embedded bundle, loading it from memory would previously take 16 ms on my laptop, and now it takes 9 ms. There are other things in this process that could be concurrent too, like JSON unmarshalling of multiple data files. But starting with parsing modules.

This PR adds errgroup as a direct dependency (previously indirect) as it is a nicer way to work with wait groups, and one that can be useful elsewhere in the codebase (like in the compiler).

Also, and as usual, went off on a bit of a tangent refactoring code related to the bundle build process, and made sure to use some common helpers in code where available.

@netlify
Copy link

netlify bot commented Nov 21, 2025

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 9c77ff0
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/69200fd97ece3f0008fc61fe
😎 Deploy Preview https://deploy-preview-8067--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Parsing is generally fast, so this mainly improves performance
of creating big bundles with many Rego files in them. For Regal's
embedded bundle, loading it from memory would previously take 16
ms on my laptop, and now it takes 9 ms. There are other things
in this process that could be concurrent too, like JSON unmarshalling
of multiple data files. But starting with parsing modules.

This PR adds `errgroup` as a direct dependency (previously indirect)
as it is a nicer way to work with wait groups, and one that can be
useful elsewhere in the codebase (like in the compiler).

Also, and as usual, went off on a bit of a tangent refactoring code
related to the bundle build process, and made sure to use some common
helpers in code where available.

Signed-off-by: Anders Eknert <[email protected]>
@anderseknert anderseknert force-pushed the concurrent-bundle-parse branch from e045403 to 9c77ff0 Compare November 21, 2025 07:08
Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Thanks for the nice side-track cleanups. Couple of questions, no blockers.

}

func (tgw *TarGzWriter) Close() error {
return errors.Join(tgw.Writer.Close(), tgw.gw.Close())
Copy link
Contributor

Choose a reason for hiding this comment

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

That's clever, but it is safe? Can we close tgw.gw when tgw.Writer.Close() returns an error? Probably, just wondering

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess worst case would be that we get two errors reported instead of one? I can certainly change this, but it does look rather neat :P

return fileInfo.Size(), nil
}

func normalizePath(p string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm I actually liked that one. It looks silly on the surface, but centralizes all our normalization efforts. If we were to add to them, do something beyond filepath.ToSlash, we could do that here. Now, we'll need to centralize them again if that happens. But it's a simple S&R, so fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed this because "normalize" means nothing I understand without looking at the implementation, whereas I don't need to do that reading ToSlash. We'll find a better name should we need to extend this later 🙂

import "strings"

// WithPrefix ensures that the string s starts with the given prefix.
// If s already starts with prefix, it is returned unchanged.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there cases where this could be undesired? What if a user-provided file happens to have the prefix, too -- is that OK or would we want it to have two prefixes for some reason?

Copy link
Member Author

Choose a reason for hiding this comment

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

If so, yes, this helper is probably not what you want. But a nice convenience when that's not the case.

@anderseknert anderseknert merged commit 51a50ca into open-policy-agent:main Nov 21, 2025
31 checks passed
@anderseknert anderseknert deleted the concurrent-bundle-parse branch November 21, 2025 07:42
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