Skip to content

perf(ax-tree): AX attribute name CFStrings are re-allocated on every tree traversal #67

@github-actions

Description

@github-actions

Problem

crates/tday-nativecore/src/platform/macos/ax.rs L507, L514–515

Helper functions like ax_children, get_string, get_bool, and get_ax_value allocate a new CFString on every call:

unsafe fn get_string(el: AXUIElementRef, attr_name: &str) -> Option<String> {
    let attr = CFString::new(attr_name); // ← allocates on every call
    ...
}

A 10,000-node AX tree snapshot calls get_string/get_bool 5–8 times per node, totalling ~50,000–80,000 CFString heap allocations per snapshot.

Suggested fix

Declare commonly used attribute names (AXRole, AXTitle, AXValue, AXDescription, AXEnabled, AXFocused, AXChildren, AXPosition, AXSize) as global lazy_static or once_cell::sync::Lazy<CFString> constants and reuse them for the lifetime of the process.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions