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

Reduce noise & improve performance of module hooks #925

Closed
Tracked by #724
radeksimko opened this issue May 23, 2022 · 1 comment · Fixed by #931
Closed
Tracked by #724

Reduce noise & improve performance of module hooks #925

radeksimko opened this issue May 23, 2022 · 1 comment · Fixed by #931
Assignees
Milestone

Comments

@radeksimko
Copy link
Member

Background

We use memdb hooks for a few use cases:

  • update telemetry data about modules
  • update diagnostics
  • refresh semantic tokens
  • update reference count code lens data
  • refresh module.calls or module.providers data

svc.stateStore.Modules.ChangeHooks = state.ModuleChangeHooks{
updateDiagnostics(svc.sessCtx, svc.diagsNotifier),
sendModuleTelemetry(svc.sessCtx, svc.stateStore, svc.telemetry),
}
svc.closedDirIndexer = scheduler.NewScheduler(&closedDirJobStore{svc.stateStore.JobStore}, 1)
svc.closedDirIndexer.SetLogger(svc.logger)
svc.closedDirIndexer.Start(svc.sessCtx)
svc.logger.Printf("running closed dir scheduler")
svc.openDirIndexer = scheduler.NewScheduler(&openDirJobStore{svc.stateStore.JobStore}, 1)
svc.openDirIndexer.SetLogger(svc.logger)
svc.openDirIndexer.Start(svc.sessCtx)
svc.logger.Printf("running open dir scheduler")
cc, err := ilsp.ClientCapabilities(ctx)
if err == nil {
if _, ok = lsp.ExperimentalClientCapabilities(cc.Experimental).ShowReferencesCommandId(); ok {
svc.stateStore.Modules.ChangeHooks = append(svc.stateStore.Modules.ChangeHooks,
refreshCodeLens(svc.sessCtx, svc.server))
}
if commandId, ok := lsp.ExperimentalClientCapabilities(cc.Experimental).RefreshModuleProvidersCommandId(); ok {
svc.stateStore.Modules.ChangeHooks = append(svc.stateStore.Modules.ChangeHooks,
callClientCommand(svc.sessCtx, svc.server, svc.logger, commandId))
}
if commandId, ok := lsp.ExperimentalClientCapabilities(cc.Experimental).RefreshModuleCallsCommandId(); ok {
svc.stateStore.Modules.ChangeHooks = append(svc.stateStore.Modules.ChangeHooks,
callClientCommand(svc.sessCtx, svc.server, svc.logger, commandId))
}
if cc.Workspace.SemanticTokens.RefreshSupport {
svc.stateStore.Modules.ChangeHooks = append(svc.stateStore.Modules.ChangeHooks,
refreshSemanticTokens(ctx, svc.srvCtx, svc.logger))
}
}

When indexing any module, there is a number of concurrent operations which can index various details about a module. This means that in practice we may end up firing any of these hooks many times repeatedly in a short time period. This affects our performance at scale - e.g. if we fire 9 RPC events for each hook, that's 6*9 = 54 events for just a single module.

Clients may deduplicate some of these requests (esp. semantic token refresh) but it represents some wasted CPU to send these requests in the first place. This may negatively impact performance especially when there's many modules being indexed.

Performance will be especially important in the context of #724

Proposal

TODO

  • queue up change events in a separate memdb table - e.g. module_events; treat module ID as unique key to deduplicate events
  • set a reasonable delay per subscriber? e.g. telemetry can be <5secs whereas UI-affecting subscribers may need <1sec
  • maintain number of subscribers VS number of notified subscribers in memdb to ensure everyone receives the update
  • leverage memdb watchers on the module_events table to subscribers having to poll
@radeksimko radeksimko self-assigned this May 23, 2022
This was referenced May 23, 2022
@radeksimko radeksimko added this to the v0.28.0 milestone May 31, 2022
@github-actions
Copy link

github-actions bot commented Jul 1, 2022

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant