Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@
## 2025-02-18 - Regex Pre-compilation in Hot Paths
**Learning:** Re-compiling regexes inside a frequently called function (like `latex_escape` which runs for every string) creates significant overhead. Pre-compiling them at module level yielded a ~3.2x speedup.
**Action:** Always look for regex compilations inside loops or frequently called functions and move them to module level constants.

## $(date +%Y-%m-%d) - Lazy Loading `yaml`

**Learning:** The `import yaml` statement at module level adds about 30ms-40ms to the startup time of all CLI commands (even `resume-cli --help`).
**Action:** Defer `import yaml` to local function scope where possible so that it is only loaded when absolutely needed. Be careful not to remove module-level imports that are needed by standard top-level logic or try/except error catching.
1 change: 0 additions & 1 deletion api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import tempfile
from pathlib import Path

import yaml
from fastapi import FastAPI, HTTPException, Response, Security
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi
Expand Down
3 changes: 1 addition & 2 deletions cli/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from pathlib import Path
from typing import Any, Dict, Optional

import yaml


def init_from_existing(
base_resume_path: Optional[Path] = None,
Expand Down Expand Up @@ -64,6 +62,7 @@ def init_from_existing(
_add_default_variants(data)

# Write YAML
import yaml
with open(output_path, "w") as f:
yaml.dump(data, f, default_flow_style=False, sort_keys=False, allow_unicode=True)

Expand Down
2 changes: 1 addition & 1 deletion cli/commands/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from typing import Optional

import click
import yaml as yaml_module


@click.command()
Expand Down Expand Up @@ -90,6 +89,7 @@ def preview(

# Load resume data
click.echo(f"Loading resume from {yaml}...")
import yaml as yaml_module
with open(yaml, "r", encoding="utf-8") as f:
resume_data = yaml_module.safe_load(f)

Expand Down
12 changes: 7 additions & 5 deletions cli/utils/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from pathlib import Path
from typing import Any, Dict, List, Optional

import yaml

# Resume YAML Schema
RESUME_SCHEMA = {
"meta": {
Expand Down Expand Up @@ -186,9 +184,13 @@ def validate_all(self) -> bool:
except FileNotFoundError as e:
self.errors.append(ValidationError("root", str(e), "error"))
return False
except yaml.YAMLError as e:
self.errors.append(ValidationError("root", f"YAML parsing error: {e}", "error"))
return False
except Exception as e:
# Replaced yaml.YAMLError to avoid importing yaml at module level
import yaml
if isinstance(e, yaml.YAMLError):
self.errors.append(ValidationError("file", f"Invalid YAML format: {str(e)}", "error"))
return False
raise

self._validate_structure(data)
self._validate_contact(data)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_validate_all_invalid_yaml(self, temp_dir: Path):

assert is_valid is False
assert len(validator.errors) > 0
assert "YAML parsing error" in validator.errors[0].message
assert "Invalid YAML format" in validator.errors[0].message

def test_validate_all_missing_required_section(self, temp_dir: Path):
"""Test validate_all detects missing required section."""
Expand Down
Loading