Skip to content

🟑 [Performance] Excessive rule evaluations per method β€” ~55 rule evaluations per methodΒ #669

@tangcent

Description

@tangcent

Problem

For a single method in SpringMvcClassExporter.exportMethod(), these rule evaluations occur:

Rule Key Count Notes
API_CLASS_PARSE_BEFORE 1 Event
API_METHOD_PARSE_BEFORE 1 Event
API_NAME 1
FOLDER_NAME 2 Method + Class
METHOD_DOC 2 Direct + via resolveApiName fallback
CLASS_DOC 1
METHOD_CONTENT_TYPE 1
METHOD_DEFAULT_HTTP 1
PATH_MULTI 1
PARAM_HTTP_TYPE N Per parameter
PARAM_NAME N Per parameter
PARAM_DOC N Per parameter
PARAM_REQUIRED N Per parameter
PARAM_IGNORE N Per parameter
PARAM_TYPE N Per parameter
PARAM_DEFAULT_VALUE N Per parameter
PARAM_DEMO N Per parameter
PARAM_MOCK N Per parameter
METHOD_ADDITIONAL_HEADER 1
METHOD_ADDITIONAL_PARAM 1
METHOD_ADDITIONAL_RESPONSE_HEADER 1
METHOD_RETURN 1
EXPORT_AFTER 1 Event
API_METHOD_PARSE_AFTER 1 Event
API_CLASS_PARSE_AFTER 1 Event

For a method with 5 parameters, that's ~55 rule evaluations per method. With 50 controllers Γ— 5 methods = 2,750 rule evaluations just for Spring MVC.

Each rule evaluation creates a RuleContext, loads expressions from config, and potentially executes Groovy scripts.

Impact

Combined with the parsers recomputation and loadExpressionsWithFilters caching issues, this compounds the overhead significantly.

Estimated speedup: 1.3-1.5x

Potential Fixes

  1. Batch related rule evaluations: resolveApiName, resolveFolderName, resolveMethodDoc could share a single RuleContext instead of creating separate ones
  2. Short-circuit when no rules configured: If loadExpressionsWithFilters(key) returns empty, skip RuleContext creation entirely
  3. Combine parameter metadata resolution: Instead of 9 separate rule evaluations per parameter, resolve all parameter metadata in a single pass
  4. Avoid duplicate evaluations: METHOD_DOC is evaluated both in resolveApiName (as fallback) and resolveMethodDoc β€” cache the result

Location

  • src/main/kotlin/com/itangcent/easyapi/exporter/springmvc/SpringMvcClassExporter.kt:90-160
  • src/main/kotlin/com/itangcent/easyapi/psi/helper/ApiMetadataResolver.kt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions