From d93c0fdf907fb2f43705cb429fd8244c9c764348 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Tue, 23 Jul 2024 21:19:20 +0800 Subject: [PATCH] chore: Document tech debt wrt multiple doc traversals (#64006) --- .../internal/lsifstore/locations_by_position.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/codeintel/codenav/internal/lsifstore/locations_by_position.go b/internal/codeintel/codenav/internal/lsifstore/locations_by_position.go index 83614cf31a9..19a552afc84 100644 --- a/internal/codeintel/codenav/internal/lsifstore/locations_by_position.go +++ b/internal/codeintel/codenav/internal/lsifstore/locations_by_position.go @@ -260,6 +260,14 @@ func symbolHoverText(symbol *scip.SymbolInformation) []string { return symbol.Documentation } +// TODO(id: doc-N-traversals): Internally, these four methods all compute the same +// exact raw data, and then they throw away most of the data. For example, the definition +// extraction logic will waste cycles by getting information about implementations. +// +// Additionally, AFAICT, each function will do a separate read of the document +// from the database and unmarshal it. This means that for the ref panel, +// we will unmarshal the same Protobuf document at least four times. :facepalm: + func (s *store) ExtractDefinitionLocationsFromPosition(ctx context.Context, locationKey LocationKey) (_ []shared.Location, _ []string, err error) { return s.extractLocationsFromPosition(ctx, extractDefinitionRanges, symbolExtractDefault, s.operations.getDefinitionLocations, locationKey) } @@ -314,8 +322,9 @@ func symbolExtractPrototype(document *scip.Document, symbolName string) (symbols return symbols } -// -// +// TODO(id: doc-N-traversals): Since this API is used in a limited number of ways, +// take some basic 'strategy' enums and implement the logic for extraction here +// so we can avoid multiple document traversals. func (s *store) extractLocationsFromPosition( ctx context.Context,