Module

analysis.performance_advisor

Performance analysis and intelligent suggestions for Bengal builds.

Analyzes build statistics and provides context-aware recommendations for improving build speed, resource usage, and developer experience.

Classes

SuggestionType
Types of performance suggestions.
0

Types of performance suggestions.

Inherits from Enum
SuggestionPriority
Priority levels for suggestions.
0

Priority levels for suggestions.

Inherits from Enum
PerformanceSuggestion dataclass
A single performance improvement suggestion. Represents an actionable recommendation to improve bu…
1

A single performance improvement suggestion.

Represents an actionable recommendation to improve build performance, with estimated impact and configuration examples.

Attributes

Name Type Description
type SuggestionType

Category of suggestion (BUILD, CONTENT, CONFIG, etc.)

priority SuggestionPriority

Priority level (HIGH, MEDIUM, LOW)

title str

Short title of the suggestion

description str

Detailed explanation of the issue

impact str

Estimated performance impact (e.g., "Could save ~2.5s")

action str

What the user should do to implement this suggestion

config_example str | None

Optional example configuration change

Internal Methods 1
__str__
Format suggestion for display.
0 str
def __str__(self) -> str

Format suggestion for display.

Returns

str

PerformanceGrade dataclass
Overall performance assessment for a build. Provides a letter grade (A-F) and category assessment …
1

Overall performance assessment for a build.

Provides a letter grade (A-F) and category assessment based on build performance metrics and best practices compliance.

Attributes

Name Type Description
grade str

Letter grade (A, B, C, D, or F)

score int

Numeric score (0-100)

category str

Performance category ("Excellent", "Good", "Fair", "Poor", "Critical")

summary str

One-line summary of performance assessment

Methods 1

calculate classmethod
Calculate performance grade based on build statistics. Scoring factors: - Buil…
1 PerformanceGrade
def calculate(cls, stats: BuildStats) -> PerformanceGrade

Calculate performance grade based on build statistics.

Scoring factors:

  • Build speed (pages/second)
  • Time distribution (balanced vs bottlenecked)
  • Cache effectiveness (if incremental)
  • Resource usage
Parameters 1
stats BuildStats
Returns

PerformanceGrade

PerformanceAdvisor
Analyzes build performance and provides intelligent suggestions. Uses build statistics to identify…
12

Analyzes build performance and provides intelligent suggestions.

Uses build statistics to identify bottlenecks and recommend optimizations tailored to the specific project.

Methods 5

analyze
Analyze build and generate suggestions.
0 list[PerformanceSug…
def analyze(self) -> list[PerformanceSuggestion]

Analyze build and generate suggestions.

Returns

list[PerformanceSuggestion]

List of suggestions, ordered by priority

get_grade
Get overall performance grade.
0 PerformanceGrade
def get_grade(self) -> PerformanceGrade

Get overall performance grade.

Returns

PerformanceGrade

PerformanceGrade with score and category

get_bottleneck
Identify the primary bottleneck phase.
0 str | None
def get_bottleneck(self) -> str | None

Identify the primary bottleneck phase.

Returns

str | None

Name of slowest phase, or None if well-balanced

get_top_suggestions
Get top N suggestions.
1 list[PerformanceSug…
def get_top_suggestions(self, limit: int = 3) -> list[PerformanceSuggestion]

Get top N suggestions.

Parameters 1
limit int

Maximum number of suggestions to return

Returns

list[PerformanceSuggestion]

Up tolimithighest-priority suggestions

format_summary
Format a text summary of analysis.
0 str
def format_summary(self) -> str

Format a text summary of analysis.

Returns

str

Multi-line string with analysis summary

Internal Methods 7
__init__
Initialize performance advisor.
2 None
def __init__(self, stats: BuildStats, environment: dict[str, Any] | None = None)

Initialize performance advisor.

Parameters 2
stats BuildStats

Build statistics to analyze

environment dict[str, Any] | None

Environment info from rich_console.detect_environment()

_check_parallel_opportunity
Check if parallel builds would help.
0 None
def _check_parallel_opportunity(self) -> None

Check if parallel builds would help.

_check_incremental_opportunity
Check if incremental builds would help.
0 None
def _check_incremental_opportunity(self) -> None

Check if incremental builds would help.

_check_rendering_bottleneck
Check if rendering is a bottleneck.
0 None
def _check_rendering_bottleneck(self) -> None

Check if rendering is a bottleneck.

_check_asset_optimization
Check asset processing performance.
0 None
def _check_asset_optimization(self) -> None

Check asset processing performance.

_check_memory_usage
Check memory usage and suggest optimizations.
0 None
def _check_memory_usage(self) -> None

Check memory usage and suggest optimizations.

_check_template_complexity
Check for template complexity issues.
0 None
def _check_template_complexity(self) -> None

Check for template complexity issues.

Functions

analyze_build
Quick analysis of build statistics.
2 PerformanceAdvisor
def analyze_build(stats: BuildStats, environment: dict[str, Any] | None = None) -> PerformanceAdvisor

Quick analysis of build statistics.

Parameters 2

Name Type Default Description
stats BuildStats

Build statistics

environment dict[str, Any] | None None

Optional environment info

Returns

PerformanceAdvisor

PerformanceAdvisor with analysis complete