]> Cypherpunks repositories - gostls13.git/commit
cmd/go: make module index loading O(1)
authorRuss Cox <rsc@golang.org>
Wed, 6 Jul 2022 13:49:32 +0000 (09:49 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 11 Jul 2022 19:09:00 +0000 (19:09 +0000)
commit7510e597def68cee77e8ba280fc0f04d3cfd2a22
treed89617bccd7cea595b88390c9e105dbdb4041940
parentb8bf820d5d4602f7e83ff89c0f8d0f2bd3a220d4
cmd/go: make module index loading O(1)

For a large module, opening the index was populating tables with
entries for every package in the module. If we are only using a small
number of those packages, this is wasted work that can dwarf the
benefit from the index.

This CL changes the index reader to avoid loading all packages
at module index open time. It also refactors the code somewhat
for clarity.

It also removes some duplication by defining that a per-package
index is a per-module index containing a single package, rather
than having two different formats and two different decoders.

It also changes the string table to use uvarint-prefixed data
instead of having to scan for a NUL byte. This makes random access
to long strings more efficient - O(1) instead of O(n) - and can significantly
speed up the strings.Compare operation in the binary search looking
for a given package.

Also add a direct test of the indexing code.

For #53577.

Change-Id: I7428d28133e4e7fe2d2993fa014896cd15af48af
Reviewed-on: https://go-review.googlesource.com/c/go/+/416178
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/go/internal/modindex/index_test.go [new file with mode: 0644]
src/cmd/go/internal/modindex/read.go
src/cmd/go/internal/modindex/write.go
src/cmd/go/internal/modload/search.go