Skip to content

Cache Environment Variables #154

@hannesdelbeke

Description

@hannesdelbeke

⚡ Cache Environment Variables

[!tip] Avoid Repeated String Lookups

Current:

def on_update(self):
    """Runs every 66ms regardless of activity"""
    if os.getenv("BQT_DISABLE_WRAP") == "1" and ...:
        bqt.manager._blender_window_change(...)
    if os.getenv("BQT_AUTO_ADD", "1") == "1":
        bqt.manager.parent_orphan_widgets(...)

Optimized:

def __init__(self):
    # Cache env var checks at startup
    self._manage_foreground = (
        os.getenv("BQT_DISABLE_WRAP") == "1" and
        os.getenv("BQT_MANAGE_FOREGROUND", "1") == "1"
    )
    self._auto_add = os.getenv("BQT_AUTO_ADD", "1") == "1"

def on_update(self):
    if self._manage_foreground and self.blender_focus_toggled():
        bqt.manager._blender_window_change(self._active_window_hwnd)

    if self._auto_add:
        bqt.manager.parent_orphan_widgets(...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions