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

Indexing: clean up ctags parser wrapper #708

Merged
merged 9 commits into from
Dec 6, 2023
Merged

Indexing: clean up ctags parser wrapper #708

merged 9 commits into from
Dec 6, 2023

Conversation

jtibshirani
Copy link
Member

@jtibshirani jtibshirani commented Dec 5, 2023

This change cleans up the Go ctags parser wrapper as a follow-up to #702. Specific changes:

  • Remove synchronization in lockedParser and rename it to CTagsParser
  • Push delegation to universal vs. SCIP ctags into parser wrapper
  • Simplify document timeout logic
  • Rename some files

Relates to https://github.com/sourcegraph/sourcegraph/issues/58112


parser := lp.parsers[typ]
recv := make(chan parseResult, 1)
go func() {
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 simplified here by using a new goroutine and channel per parse request. It looked totally fine in benchmarks, but maybe this is bad practice. Any thoughts?

return resp.entries, resp.err
case <-deadline.C:
// Error out since ctags hanging is a sign something bad is happening.
return nil, fmt.Errorf("ctags timedout after %s parsing %s", parseTimeout, name)
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 decided to make this a hard error, in contrast to before where if require_ctags was not set, we attempted to restart the ctags process and move to the next document. It felt better to keep this simple, especially since we always enable require_ctags by default.

Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

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

nice!

ctags/json.go Show resolved Hide resolved
ctags/json.go Outdated
Comment on lines 65 to 67
func (lp *CTagsParser) Close() {
for _, parser := range lp.parsers {
parser.Close()
Copy link
Member

Choose a reason for hiding this comment

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

the old implementation protected from calling lp.p.Close twice. Not sure if that is needed given Close likely can be called twice. Just checking :)

Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding: because of how parser.Close() is implemented, it is okay to call twice. I just tested this by adding an extra call to parser.Close() during indexing and it was fine. Also, we do try to structure things so that parser.Close() should ever only be called once.

ctags/json.go Outdated Show resolved Hide resolved
ctags/json.go Outdated
Comment on lines 65 to 68
go func() {
entry, err := parser.Parse(name, content)
recv <- parseResult{entries: entry, err: err}
}()
Copy link
Member

Choose a reason for hiding this comment

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

I think the overhead of a new goroutine is likely fine given we know ctags is already the bottleneck. I'd be interested to know if it pops up in profiles now.

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 didn't see any difference in job latency or in the CPU profiles

ctags/parser.go Outdated Show resolved Hide resolved
@jtibshirani
Copy link
Member Author

Thanks for the review!

@jtibshirani jtibshirani merged commit 7b678e1 into main Dec 6, 2023
8 checks passed
@jtibshirani jtibshirani deleted the jtibs/parser branch December 6, 2023 16:53
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