-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add concurrency to mdformatter
#63
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Saswata Mukherjee <[email protected]>
7e0ee53
to
ff64d28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far! Thanks, some comments.
@@ -240,57 +241,73 @@ func IsFormatted(ctx context.Context, logger log.Logger, files []string, opts .. | |||
|
|||
func format(ctx context.Context, logger log.Logger, files []string, diffs *Diffs, spin *yacspin.Spinner, opts ...Option) error { | |||
f := New(ctx, opts...) | |||
b := bytes.Buffer{} | |||
// TODO(bwplotka): Add concurrency (collector will need to redone). | |||
errorChannel := make(chan error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errorChannel := make(chan error) | |
errorCh := make(chan error) |
spin.Message(fn + "...") | ||
} | ||
errs.Add(func() error { | ||
go func(fn string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use https://pkg.go.dev/golang.org/x/sync/errgroup maybe, so semantics are easier.
return | ||
} | ||
v.destFutures[k] = &futureResult{cases: 1, resultFn: func() error { return nil }} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a race during replacement operation.
@@ -34,7 +34,11 @@ func (v GitHubValidator) IsValid(k futureKey, r *validator) (bool, error) { | |||
// RoundTripValidator.IsValid returns true if url is checked by colly. | |||
func (v RoundTripValidator) IsValid(k futureKey, r *validator) (bool, error) { | |||
// Result will be in future. | |||
r.destFutures[k].resultFn = func() error { return r.remoteLinks[k.dest] } | |||
prevResult, _ := r.destFutures.LoadAndDelete(k) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lot's of races when we delete, unfortunately.. we need to make this operation locked potentially with Mutex.
But it has to be the full operation Locked:
- Checking if there is entry in map
- If no, create new future, and schedule colly
- If yes, grab reference to future
We might need to check IsValid
interface, if this actually allows us to do this 🤔
Still comments not addressed, I believe? |
Any progress? |
This PR parallelizes the file processing loop in
mdformatter
for faster formatting and link checking usingWaitGroup
by spawning a goroutine for each file. (This also changes CLI spinner behavior as filenames cannot be shown due to multiple files being processed at once)Some caveats,
v.c.Wait()
(flaky, maybe due to internal colly WaitGroup)