-
Notifications
You must be signed in to change notification settings - Fork 11
Reduce scan startup time in large repositories #301
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
Open
lelia
wants to merge
15
commits into
main
Choose a base branch
from
lelia/reduce-scan-startup-time
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
78b6356
perf(core): discover manifests in a single filesystem walk
lelia 04db555
perf(git): fetch only the refs a comparison needs
lelia 33d616c
feat(buildkite): derive GitHub comment context natively
lelia 312dcf9
refactor(cli): reuse sub-path discovery results and clarify scan routing
lelia 4a5c9f1
docs(changelog): note faster local scan setup for large repositories
lelia 85ea858
chore(release): bump version to 2.6.5
lelia 7270bde
fix(ci): build the Docker preview from the checked-out workspace
lelia 0fc1cb3
ci(preview): build Docker previews for arm64 as well as amd64
lelia da788bf
perf(diff): tighten diff-scan poll ceiling and make its timing attrib…
lelia 74a549b
feat(diff): log the diff report URL and cover discovery memory
lelia 40b141e
docs(diff): record verified cached diff-scan param behaviour
lelia 3d2b9bf
perf(diff): skip unchanged artifacts when no output reads them
lelia ded18f2
Merge remote-tracking branch 'origin/main' into lelia/reduce-scan-sta…
lelia 2315da3
chore(release): bump version to 2.6.6
lelia a7c6ba3
fix: always filter diff scan artifacts
lelia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #!/usr/bin/env python3 | ||
| """Compare legacy per-pattern rglob discovery with the single-pass walker. | ||
|
|
||
| This is an opt-in developer benchmark, not a timing assertion in the test | ||
| suite. It creates a synthetic monorepo so filesystem or CI-agent changes do not | ||
| make regular tests flaky. | ||
| """ | ||
|
|
||
| import argparse | ||
| import tempfile | ||
| import time | ||
| from pathlib import Path | ||
| from types import SimpleNamespace | ||
| from unittest.mock import MagicMock | ||
|
|
||
| from socketsecurity.core import Core | ||
| from socketsecurity.core.socket_config import SocketConfig | ||
| from socketsecurity.core.utils import socket_globs | ||
|
|
||
|
|
||
| def seed_tree(root: Path, directories: int, files_per_directory: int) -> None: | ||
| for directory_index in range(directories): | ||
| directory = root / "packages" / f"package-{directory_index:05d}" | ||
| directory.mkdir(parents=True) | ||
| (directory / "package.json").write_text("{}\n", encoding="utf-8") | ||
| for file_index in range(files_per_directory): | ||
| (directory / f"source-{file_index:03d}.txt").write_text( | ||
| "not a manifest\n", | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
| # These trees model the expensive directories that the new walker prunes | ||
| # before descent rather than visiting once for every manifest pattern. | ||
| for excluded in (".git/objects", "node_modules/example", ".venv/site-packages"): | ||
| directory = root / excluded | ||
| directory.mkdir(parents=True) | ||
| for index in range(files_per_directory * 10): | ||
| (directory / f"object-{index:05d}").write_text("x", encoding="utf-8") | ||
|
|
||
|
|
||
| def legacy_discover(root: Path) -> set[str]: | ||
| results = set() | ||
| excluded_dirs = SocketConfig(api_key="benchmark").excluded_dirs | ||
| for ecosystem_patterns in socket_globs.values(): | ||
| for details in ecosystem_patterns.values(): | ||
| for pattern in Core.expand_brace_pattern(details["pattern"]): | ||
| insensitive = Core.to_case_insensitive_regex(pattern) | ||
| for candidate in root.rglob(insensitive): | ||
| if candidate.is_file() and not Core.is_excluded( | ||
| str(candidate), | ||
| excluded_dirs, | ||
| ): | ||
| results.add(candidate.as_posix()) | ||
| return results | ||
|
|
||
|
|
||
| def new_core() -> Core: | ||
| core = Core.__new__(Core) | ||
| core.config = SocketConfig(api_key="benchmark") | ||
| core.cli_config = SimpleNamespace(exclude_paths=None) | ||
| core.sdk = MagicMock() | ||
| core._supported_patterns = socket_globs | ||
| return core | ||
|
|
||
|
|
||
| def timed(function, root: Path) -> tuple[set[str], float]: | ||
| start = time.perf_counter() | ||
| results = set(function(root)) | ||
| return results, time.perf_counter() - start | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--directories", type=int, default=500) | ||
| parser.add_argument("--files-per-directory", type=int, default=20) | ||
| args = parser.parse_args() | ||
|
|
||
| with tempfile.TemporaryDirectory(prefix="socket-manifest-benchmark-") as temp: | ||
| root = Path(temp) | ||
| seed_tree(root, args.directories, args.files_per_directory) | ||
| legacy_results, legacy_seconds = timed(legacy_discover, root) | ||
| new_results, new_seconds = timed( | ||
| lambda path: new_core().find_files(str(path)), | ||
| root, | ||
| ) | ||
|
|
||
| if legacy_results != new_results: | ||
| raise SystemExit( | ||
| "Manifest result mismatch: " | ||
| f"legacy={len(legacy_results)}, single_pass={len(new_results)}" | ||
| ) | ||
|
|
||
| speedup = legacy_seconds / new_seconds if new_seconds else float("inf") | ||
| print(f"Manifests: {len(new_results)}") | ||
| print(f"Legacy per-pattern rglob: {legacy_seconds:.3f}s") | ||
| print(f"Single-pass walk: {new_seconds:.3f}s") | ||
| print(f"Speedup: {speedup:.1f}x") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| __author__ = 'socket.dev' | ||
| __version__ = '2.6.5' | ||
| __version__ = '2.6.6' | ||
| USER_AGENT = f'SocketPythonCLI/{__version__}' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this can be trimmed a bit. Claude likes to include a lot of details from the problem investigation, which is maybe not necessary for a user-facing changelog.