Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ Speed up is_truthy() by 49% in posthog/hogql/database/schema/util/where_clause_extractor.py #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Jun 29, 2024

  1. ⚡️ Speed up is_truthy() by 49%

    #### Why these changes?
    - The initial code was simplified by merging the logic of `is_not_truthy` into `is_truthy`.
    - The code was further optimized by using set membership for a concise and efficient check.
    - Finally, separate condition checks were used in the better micro-optimized code to ensure optimal performance.
    
    #### Correctness
    - The logic remains the same: to determine if a value is truthy or not.
    - All branches (`False`, `None`, `0`) are still correctly identified.
    
    #### How is this faster?
    - Using a set for membership tests leverages average O(1) time complexity.
    - Checking conditions separately can avoid unnecessary overhead in some cases.
    - Overall, the code is both more readable and performant without changing the results or side effects.
    codeflash-ai[bot] authored Jun 29, 2024
    Configuration menu
    Copy the full SHA
    266b123 View commit details
    Browse the repository at this point in the history