Files
cleveragents-core/benchmarks/resource_cli_tree_bench.py
T
brent.edwards b88bc0ec1b
CI / build (push) Successful in 19s
CI / lint (push) Successful in 3m19s
CI / quality (push) Successful in 3m43s
CI / typecheck (push) Successful in 3m55s
CI / security (push) Successful in 4m2s
CI / unit_tests (push) Successful in 6m39s
CI / integration_tests (push) Successful in 6m48s
CI / docker (push) Successful in 1m7s
CI / e2e_tests (push) Successful in 9m7s
CI / benchmark-regression (push) Has been skipped
CI / coverage (push) Failing after 16m36s
CI / benchmark-publish (push) Successful in 25m51s
CI / status-check (push) Failing after 4s
feat(perf): large project scaling tests (#984)
## Summary

Add large project scaling benchmarks and tests at production scale (10K–100K files).

### New ASV Benchmarks

**IndexingScalingSuite** (`large_project_scaling_bench.py`):
- `time_walk_and_index` at 1K/10K/50K/100K files
- `time_incremental_refresh` (1% modified files)
- `track_indexed_file_count`, `track_tokens_per_second`

**ContextAssemblyScalingSuite** (`context_assembly_scaling_bench.py`):
- `time_full_pipeline` at 100/1K/5K/10K fragments
- `time_tiered_strategy`, `time_recency_strategy`
- `track_assembled_tokens`, `track_fragments_per_second`

**ExecutionThroughputSuite** (`execution_throughput_bench.py`):
- `time_sequential_plans` at 10/50/100 plans
- `time_executor_construction`, `time_decision_tree_scaling`

### Scale Fixture Updates

- Added `xlarge` (50K files) and `xxlarge` (100K files) profiles to `scale_metadata.json`
- Added 50K/100K thresholds to `baseline_thresholds.json`
- Added `context_assembly` and `execution_throughput` threshold sections

### Tests & Documentation

- 15 Behave scenarios validating profiles, thresholds, monotonicity, memory budgets
- 6 Robot integration tests including live 1K-file indexing throughput check
- `docs/reference/scaling_baselines.md` documenting all baseline metrics

### Quality Gates

| Session | Result |
|---|---|
| `nox -s lint` | PASS |
| `nox -s typecheck` | PASS (0 errors) |
| `nox -s unit_tests` | PASS (10,910 scenarios) |
| `nox -s integration_tests` | PASS (1,526 tests) |
| `nox -s coverage_report` | 97% (>= 97%) |

Closes #859

Reviewed-on: #984
Co-authored-by: Brent E. Edwards <brent.edwards@cleverthis.com>
Co-committed-by: Brent E. Edwards <brent.edwards@cleverthis.com>
2026-03-21 04:46:45 +00:00

175 lines
5.4 KiB
Python

"""ASV benchmarks for Resource CLI tree/inspect command overhead.
Measures the performance of:
- Tree rendering for a resource with no children
- Tree rendering for a resource with multiple children
- Inspect command rendering
- Link-child / unlink-child command throughput
"""
from __future__ import annotations
import importlib
import sys
from datetime import UTC, datetime
from pathlib import Path
from unittest.mock import MagicMock, patch
# Ensure the local *source* tree is importable even when ASV has an
# older build of the package installed.
_SRC = str(Path(__file__).resolve().parents[1] / "src")
if _SRC not in sys.path:
sys.path.insert(0, _SRC)
import cleveragents # noqa: E402
importlib.reload(cleveragents)
from typer.testing import CliRunner # noqa: E402
from cleveragents.cli.commands.resource import app as resource_app # noqa: E402
from cleveragents.domain.models.core.resource import ( # noqa: E402
PhysVirt,
Resource,
ResourceCapabilities,
)
_runner = CliRunner()
def _mock_resource(
resource_id: str = "01HBENCH0000000000RES0RCE0",
name: str = "local/bench-res",
type_name: str = "git-checkout",
) -> Resource:
return Resource(
resource_id=resource_id,
name=name,
resource_type_name=type_name,
classification=PhysVirt.PHYSICAL,
description="Benchmark resource",
properties={"path": "/tmp/bench"},
location="/tmp/bench",
content_hash=None,
sandbox_strategy=None,
capabilities=ResourceCapabilities(),
created_at=datetime.now(tz=UTC),
updated_at=datetime.now(tz=UTC),
)
def _mock_tree_node(
resource: Resource,
children: list[dict[str, object]] | None = None,
) -> dict[str, object]:
return {
"resource": resource,
"children": children or [],
}
class ResourceTreeSuite:
"""Benchmark resource tree command throughput."""
def setup(self) -> None:
"""Set up mock service."""
root = _mock_resource()
child1 = _mock_resource(
"01HBENCH0000000000CHILD001", "local/child-1", "fs-directory"
)
child2 = _mock_resource(
"01HBENCH0000000000CHILD002", "local/child-2", "fs-directory"
)
tree = [
_mock_tree_node(
root,
[
_mock_tree_node(child1),
_mock_tree_node(child2),
],
)
]
self._mock_service = MagicMock()
self._mock_service.get_resource_tree.return_value = tree
self._mock_service.show_resource.return_value = root
self._patcher = patch(
"cleveragents.cli.commands.resource._get_registry_service",
return_value=self._mock_service,
)
self._patcher.start()
def teardown(self) -> None:
self._patcher.stop()
def time_tree_default(self) -> None:
"""Benchmark tree with default settings."""
_runner.invoke(resource_app, ["tree", "local/bench-res"])
def time_tree_json(self) -> None:
"""Benchmark tree with JSON output."""
_runner.invoke(resource_app, ["tree", "local/bench-res", "--format", "json"])
def time_tree_depth(self) -> None:
"""Benchmark tree with depth limit."""
_runner.invoke(resource_app, ["tree", "local/bench-res", "--depth", "1"])
class ResourceInspectSuite:
"""Benchmark resource inspect command throughput."""
def setup(self) -> None:
"""Set up mock service."""
res = _mock_resource()
tree = [_mock_tree_node(res)]
self._mock_service = MagicMock()
self._mock_service.show_resource.return_value = res
self._mock_service.get_resource_tree.return_value = tree
self._patcher = patch(
"cleveragents.cli.commands.resource._get_registry_service",
return_value=self._mock_service,
)
self._patcher.start()
def teardown(self) -> None:
self._patcher.stop()
def time_inspect_default(self) -> None:
"""Benchmark inspect with default settings."""
_runner.invoke(resource_app, ["inspect", "local/bench-res"])
def time_inspect_json(self) -> None:
"""Benchmark inspect with JSON output."""
_runner.invoke(resource_app, ["inspect", "local/bench-res", "--format", "json"])
def time_inspect_with_tree(self) -> None:
"""Benchmark inspect with --tree flag."""
_runner.invoke(resource_app, ["inspect", "local/bench-res", "--tree"])
class ResourceLinkSuite:
"""Benchmark resource link-child/unlink-child command throughput."""
def setup(self) -> None:
"""Set up mock service."""
self._mock_service = MagicMock()
self._mock_service.link_child.return_value = None
self._mock_service.unlink_child.return_value = None
self._patcher = patch(
"cleveragents.cli.commands.resource._get_registry_service",
return_value=self._mock_service,
)
self._patcher.start()
def teardown(self) -> None:
self._patcher.stop()
def time_link_child(self) -> None:
"""Benchmark link-child command."""
_runner.invoke(resource_app, ["link-child", "local/parent", "local/child"])
def time_unlink_child(self) -> None:
"""Benchmark unlink-child command."""
_runner.invoke(
resource_app, ["unlink-child", "--yes", "local/parent", "local/child"]
)