Skip to content

Conversation

@srenatus
Copy link
Contributor

@srenatus srenatus commented Dec 2, 2025

Adapted to what we've merged since my previous experiment. Notable changes:

  1. If there's only one module, don't bother with goroutines.
  2. Less sloppy handling of booleans set in the stages -- they're all (🤞) atomic.Bools now.
  3. None of the grouping bits I had experimented with in experiment: per-module fan-out in compiler stages #8063. It's working, but it's so much more cumbersome for little effect.
  4. It's using errgroup -- not because it would return an error, but because it's almost like waitgroup.Go() but without having to bump the lower bound golang version.

Supersedes #8063.

@srenatus srenatus force-pushed the sr/zmuspzxlsvxo branch 2 times, most recently from ea436d0 to 5cd3ad2 Compare December 2, 2025 13:34
@netlify
Copy link

netlify bot commented Dec 2, 2025

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit a56e1e0
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/692eea2c4badf7000899fadf
😎 Deploy Preview https://deploy-preview-8102--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.

@srenatus srenatus requested a review from anderseknert December 2, 2025 13:36
@netlify
Copy link

netlify bot commented Dec 2, 2025

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit ea436d0
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/692eea5976459b00074d00dd
😎 Deploy Preview https://deploy-preview-8102--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.

@netlify
Copy link

netlify bot commented Dec 2, 2025

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit f622135
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/6932bbab43ec3a00083cd873
😎 Deploy Preview https://deploy-preview-8102--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.

@srenatus srenatus force-pushed the sr/zmuspzxlsvxo branch 3 times, most recently from b0efc9e to 4abf66c Compare December 5, 2025 10:05
c := NewCompiler()
for i, m := range tc.modules {
c.Modules[strconv.Itoa(i)] = m
c.sorted = append(c.sorted, strconv.Itoa(i))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These weren't necessary: compileStages already does that. It's also harmful, since if c.sorted contains the same module twice, we'll run the stages concurrently on the same module, causing a data race.

@srenatus srenatus marked this pull request as ready for review December 5, 2025 10:07
Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
f := newEqualityFactory(c.localvargen)
// NB(sr): This stage cannot be run concurrently: the GenericTransformer "writes" rule heads
// that the validateWith() method reads. If we had a more specialized transformer here that would
// leave the heads untouched, we could run it concurrently.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

☝️ I had to back out here. I thought this was OK, but the race detection with v1/topdown taught me it's not 😅

Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

Let's goooo!

for _, name := range c.sorted {
g.Go(func() error { f(c.Modules[name]); return nil })
}
_ = g.Wait()
Copy link
Member

Choose a reason for hiding this comment

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

I guess using an errgroup here doesn't add much over a wait group since we delegate error handling. But it also doesn't hurt :)

}
}
g := &errgroup.Group{}
for _, name := range c.sorted {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider limiting the errgroup concurrency when processing large slices to avoid excessive goroutine creation. You could use g.SetLimit(runtime.GOMAXPROCS(0)) or conditionally set a limit based on the slice size:

if len(c.sorted) > runtime.GOMAXPROCS(0) {
    g.SetLimit(runtime.GOMAXPROCS(0))
}

This will prevent spawning thousands of goroutines for large datasets and improve memory efficiency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually had considered that, but it didn't move the needle at all in my benchmarks. So I went back to the simple approach.

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.

3 participants