Skip to content

Conversation

@hfudev
Copy link
Member

@hfudev hfudev commented May 21, 2025

No description provided.

@hfudev hfudev requested review from Copilot and horw May 21, 2025 12:41
@hfudev hfudev self-assigned this May 21, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR aims to improve performance in the bool_parser module by adding caching and streamlining logical operations. Key changes include:

  • Introducing the lru_cache decorator on various get_value methods to cache results.
  • Replacing iterative for-loops with list comprehensions, built-in any(), and all() for concise logical evaluations.
  • Refactoring code in BoolOr and BoolAnd classes to enhance clarity and efficiency.
Comments suppressed due to low confidence (1)

esp_bool_parser/bool_parser.py:70

  • Ensure that caching via lru_cache on instance methods is appropriate; since the instance (self) is part of the cache key, any changes to instance state won't invalidate the cache. Verify that instances remain effectively immutable or update the caching strategy accordingly.
@lru_cache

@hfudev hfudev force-pushed the perf/improve-performance branch from ebaa554 to 9de9a5f Compare May 21, 2025 13:24
@github-actions
Copy link

Coverage

Coverage Report
FileStmtsMissCoverMissing
esp_bool_parser
   bool_parser.py1191885%50, 76, 79, 82, 94–108, 170, 175, 183, 187
   constants.py411368%19–20, 45–57
   soc_header.py684140%54–64, 77–82, 86–93, 97–138
   utils.py24292%76–77
TOTAL2597471% 

Tests Skipped Failures Errors Time
52 1 💤 0 ❌ 0 🔥 0.798s ⏱️

@hfudev hfudev requested a review from Copilot May 21, 2025 13:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR aims to improve performance by leveraging caching and more concise iterations in boolean evaluation methods.

  • Added lru_cache decorators to multiple get_value instance methods to cache computed results.
  • Replaced explicit for-loops with Python built-ins (any and all) to improve clarity and performance.

def __init__(self, t: ParseResults):
self.attr: str = t[0]

@lru_cache(None)
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using lru_cache on instance methods can lead to unexpected behavior if the instance (self) is mutable or not hashable. Consider ensuring that instances remain immutable or refactoring the caching mechanism to operate on a function that receives only hashable parameters.

Copilot uses AI. Check for mistakes.
@hfudev hfudev merged commit e180144 into main May 21, 2025
4 checks passed
@hfudev hfudev deleted the perf/improve-performance branch May 21, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants