perf(gateway): parse readiness and bundled-manifest YAML with the C loader
Same class as the config/manifest loader swap earlier in this stack. The /ready probe re-read and pure-Python-parsed config.yaml on every poll, inside the aiohttp handler (110 KB seeded config: 2332 -> 487 ms per probe on a loaded runner). It now uses utils.load_yaml_file_readonly: the C loader, and repeat probes reuse the parse until the file signature changes. Parse errors are not cached, so an edit that breaks or fixes the file shows on the next probe. The bundled-platform manifest reader was the one startup manifest reader left on yaml.safe_load. managed_scope imports fast_safe_load at module level next to file_signature instead of lazily.
This commit is contained in:
@@ -19,7 +19,7 @@ from gateway.shutdown_watchdog import (
|
||||
DEFAULT_LOOP_WATCHDOG_MAX_STRIKES,
|
||||
DEFAULT_LOOP_WATCHDOG_TIMEOUT_S,
|
||||
)
|
||||
from utils import is_truthy_value
|
||||
from utils import fast_safe_load, is_truthy_value
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -177,12 +177,11 @@ _Platform__bundled_plugin_aliases: Optional[dict] = None # manifest ``name:`` (
|
||||
def _bundled_platform_manifest_name(plugin_dir: Path) -> Optional[str]:
|
||||
"""Lowercased ``name:`` from a bundled platform's plugin manifest (None when absent/unreadable)."""
|
||||
try:
|
||||
import yaml
|
||||
manifest_file = next(
|
||||
(plugin_dir / m for m in ("plugin.yaml", "plugin.yml") if (plugin_dir / m).exists()), None)
|
||||
if manifest_file is None:
|
||||
return None
|
||||
data = yaml.safe_load(manifest_file.read_text(encoding="utf-8")) or {}
|
||||
data = fast_safe_load(manifest_file.read_text(encoding="utf-8")) or {}
|
||||
name = data.get("name") if isinstance(data, dict) else None
|
||||
return str(name).strip().lower() or None
|
||||
except Exception:
|
||||
|
||||
@@ -8,9 +8,8 @@ from contextlib import closing
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
|
||||
from hermes_constants import get_hermes_home
|
||||
from utils import load_yaml_file_readonly
|
||||
|
||||
|
||||
_DISK_DEGRADED_PERCENT = 90.0
|
||||
@@ -55,7 +54,7 @@ def _probe_config(home: Path) -> dict[str, Any]:
|
||||
if not path.exists():
|
||||
return _check("ok", "using defaults")
|
||||
try:
|
||||
raw = yaml.safe_load(path.read_text(encoding="utf-8"))
|
||||
raw = load_yaml_file_readonly(path)
|
||||
except Exception as exc:
|
||||
return _check("degraded", f"invalid config ({type(exc).__name__})")
|
||||
return _check("ok") if raw is None or isinstance(raw, dict) else _check("degraded", "top level is not a mapping")
|
||||
|
||||
@@ -23,7 +23,7 @@ from hermes_cli.stale_modules import drop_stale_root_modules
|
||||
|
||||
drop_stale_root_modules()
|
||||
|
||||
from utils import file_signature
|
||||
from utils import fast_safe_load, file_signature
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -106,7 +106,6 @@ def _load_managed_file(name: str, cache: Dict[str, tuple], parse) -> dict:
|
||||
|
||||
def load_managed_config() -> dict:
|
||||
"""Parsed managed config.yaml, or {} when absent/malformed (fail-open)."""
|
||||
from utils import fast_safe_load
|
||||
|
||||
return _load_managed_file("config.yaml", _CONFIG_CACHE, lambda p: fast_safe_load(p.read_text(encoding="utf-8")) or {})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user