Skip to content

directives_meta.py: simplify _remove_directives#51858

Merged
alalazo merged 1 commit intodevelopfrom
hs/fix/directives-simplify
Jan 19, 2026
Merged

directives_meta.py: simplify _remove_directives#51858
alalazo merged 1 commit intodevelopfrom
hs/fix/directives-simplify

Conversation

@haampie
Copy link
Copy Markdown
Member

@haampie haampie commented Jan 16, 2026

  • Since the input arg is a tuple/list, start with iteration, avoiding
    one level of guaranteed recursion and an isinstance check.
  • Avoid the generator expression which uses another stack frame,
    as well as capturing arg in a cell, which is then de-referenced
    more than a million times (hottest LOAD_DEREF instruction in
    Spack).

Saves about 0.3s for me in practice. Not much, but better than nothing.

(The whole _remove_directives function is rather unfortunate, adding
500ms of overhead. Not sure if it can easily be improved other than
"leaky abstractions" targeting it to depends_on directives, and
looking for the patches kwarg. This PR just optimizes the existing
implementation)

* Since the input arg is a tuple/list, start with iteration, avoiding
  one level of guaranteed recursion and an `isinstance` check.
* Avoid the generator expression which makes Python cycle between two
  stack frames and doing another function call. Instead use native
  iteration.

The whole `_remove_directives` function is rather unfortunate, adding
500ms of overhead. Not sure if it can easily be improved other than
"leaky abstractions" (targeting it to `depends_on` directives, and
looking for the `patches` kwarg). I'll just leave it optimizing the
current implementation.

Signed-off-by: Harmen Stoppels <[email protected]>
@alalazo
Copy link
Copy Markdown
Member

alalazo commented Jan 19, 2026

There are nasty details, but they are well commented, so LGTM

@alalazo alalazo merged commit c516610 into develop Jan 19, 2026
31 of 32 checks passed
@alalazo alalazo deleted the hs/fix/directives-simplify branch January 19, 2026 09:18
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