#58: the discovery walk runs in 512-entry slices with requests drained between them (lucisv_core ResumableWalk, state/walking.rs); identities are read in one pass at landing. Proved equal to the one-shot walk. #64: the 40k rescan timing split is not reproducible; the store is kept across rescans, compaction streams, candidates are cheaper (-12% on 40k, answers and store byte-identical). Files topo #71-#74. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
This commit is contained in:
1 parent
dc54b23572
commit
36733e2c7c
29 files changed
+3520
-126
No files matched your search
@@ -0,0 +1,137 @@
|
||||
# Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
"""What a session answers before and after its rescans, as hashes to diff
|
||||
between two `lucisv-server` binaries — the differential behind
|
||||
`docs/features/server-scaling-r10/README.md`.
|
||||
|
||||
tools/guard.sh -m 8 -t 1200 -- python3 tools/perf/rescan_diff.py \
|
||||
--server target/release/lucisv-server --tree ~/repo/opentitan/hw \
|
||||
--open ip/aes/rtl/aes_cipher_core.sv --storage "$SCRATCH/diff-new" \
|
||||
--rescans 2 > "$SCRATCH/new.txt"
|
||||
|
||||
One cold session at workspace scope (`--storage` is emptied first): the
|
||||
startup scan, then `--rescans` whole rescans, each a settings push alternating
|
||||
an exclude that names nothing — so every rescan reads the same tree and writes
|
||||
nothing into it, and the corpus stays read-only. After the startup scan and
|
||||
after every rescan it prints one line per answer — workspace symbols, the
|
||||
module hierarchy, the open buffer's outline and every definition, hover and
|
||||
reference answer at a few cursors — with the SHA-256 of the answer's JSON;
|
||||
at the end the SHA-256 and size of the index store file. `--storage` is
|
||||
emptied only when it is absent, empty or a lucisv store; anything else is
|
||||
refused. Two binaries that
|
||||
agree print the same lines. Python 3 standard library only.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from lspclient import Session, uri # noqa: E402
|
||||
from rescan import FINISHED, finished, wait_log # noqa: E402
|
||||
|
||||
QUERIES = ["aes", "prim_", "tl_", "u", "reg"]
|
||||
|
||||
|
||||
def digest(value):
|
||||
return hashlib.sha256(json.dumps(value, sort_keys=True).encode()).hexdigest()[:16]
|
||||
|
||||
|
||||
def cursors(path, count=8):
|
||||
"""Up to `count` (line, character) positions on names worth asking about
|
||||
in `path`: package references, instance names, ports and signals with an
|
||||
underscore, the first of each, never inside a comment."""
|
||||
wanted = re.compile(r"\b(?:\w+_pkg|u_\w+|\w+_[io]|\w+_q|\w+_d)\b")
|
||||
found, seen = [], set()
|
||||
with open(path, encoding="utf-8", errors="replace") as handle:
|
||||
for line_no, line in enumerate(handle):
|
||||
code = line.split("//", 1)[0]
|
||||
for match in wanted.finditer(code):
|
||||
if match.group(0) in seen:
|
||||
continue
|
||||
seen.add(match.group(0))
|
||||
found.append((line_no, match.start() + 1))
|
||||
if len(found) >= count:
|
||||
return found
|
||||
return found
|
||||
|
||||
|
||||
def answers(s, opened, step):
|
||||
"""Print one line per answer, `step` naming when it was asked."""
|
||||
asked = [("workspace/symbol", {"query": q}) for q in QUERIES]
|
||||
asked.append(("lucisv/moduleHierarchy", {}))
|
||||
asked.append(("textDocument/documentSymbol", {"textDocument": {"uri": uri(opened)}}))
|
||||
for line, character in cursors(opened):
|
||||
for method in ("textDocument/definition", "textDocument/hover",
|
||||
"textDocument/references"):
|
||||
params = {"textDocument": {"uri": uri(opened)},
|
||||
"position": {"line": line, "character": character},
|
||||
"context": {"includeDeclaration": True}}
|
||||
asked.append((method, params))
|
||||
for method, params in asked:
|
||||
_, message = s.request(method, params)
|
||||
result = message.get("result", message.get("error"))
|
||||
where = params.get("query", params.get("position", ""))
|
||||
print("%s %s %s %s" % (step, method, json.dumps(where, sort_keys=True), digest(result)))
|
||||
|
||||
|
||||
def clear_store(path):
|
||||
"""Empty `path` for a cold session — only when it is absent, empty, or
|
||||
holds nothing but what a lucisv index store writes (`index-cache`, its
|
||||
`.gitignore`, a leftover `index-cache.<pid>.tmp`). Anything else is a
|
||||
mistyped path and is refused rather than deleted."""
|
||||
if not os.path.exists(path):
|
||||
return
|
||||
if not os.path.isdir(path):
|
||||
sys.exit("rescan_diff: --storage %s is not a directory; refusing to delete it" % path)
|
||||
names = os.listdir(path)
|
||||
store = lambda n: n in ("index-cache", ".gitignore") or (
|
||||
n.startswith("index-cache.") and n.endswith(".tmp"))
|
||||
strangers = [n for n in names if not store(n)]
|
||||
if strangers:
|
||||
sys.exit("rescan_diff: --storage %s holds %s, not a lucisv store; refusing to delete it"
|
||||
% (path, ", ".join(sorted(strangers)[:5])))
|
||||
shutil.rmtree(path)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("--server", required=True)
|
||||
parser.add_argument("--tree", required=True)
|
||||
parser.add_argument("--open", required=True)
|
||||
parser.add_argument("--storage", required=True)
|
||||
parser.add_argument("--rescans", type=int, default=2)
|
||||
args = parser.parse_args()
|
||||
tree = os.path.abspath(args.tree)
|
||||
clear_store(args.storage)
|
||||
opened = os.path.join(tree, args.open)
|
||||
with Session(args.server, tree, args.storage, scope={"index": {"scope": "workspace"}},
|
||||
verbose=True) as s:
|
||||
s.initialize()
|
||||
s.did_open(opened)
|
||||
wait_log(s, 0, lambda t: t.startswith(FINISHED))
|
||||
s.wait_quiet(1.0)
|
||||
answers(s, opened, "startup")
|
||||
for k in range(args.rescans):
|
||||
s.drain()
|
||||
start = len(s.log_messages)
|
||||
s.scope = {"index": {"scope": "workspace"}, "exclude": ["zz_no_such_%d" % (k % 2)]}
|
||||
s.notify("workspace/didChangeConfiguration", {"settings": {"lucisv": s.scope}})
|
||||
finished(s, start)
|
||||
s.wait_quiet(0.5)
|
||||
answers(s, opened, "rescan%d" % k)
|
||||
store = os.path.join(args.storage, "index-cache")
|
||||
with open(store, "rb") as handle:
|
||||
data = handle.read()
|
||||
print("store %d %s" % (len(data), hashlib.sha256(data).hexdigest()))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
Reference in new issue
Block a user