Skip to content

Optimize hasAttribute to avoid unnecessary list allocation#222

Open
Copilot wants to merge 3 commits intodevelopfrom
copilot/optimize-hasattribute-implementation
Open

Optimize hasAttribute to avoid unnecessary list allocation#222
Copilot wants to merge 3 commits intodevelopfrom
copilot/optimize-hasattribute-implementation

Conversation

Copy link

Copilot AI commented Mar 19, 2026

  • Replace hasAttribute implementation in src/cil.ml to use List.exists instead of filterAttributes to avoid unnecessary list allocation
  • Remove obsolete (* sm: *) comment before hasAttribute
Original prompt

This section details on the original issue you should resolve

<issue_title>Optimize hasAttribute</issue_title>
<issue_description>It's currently implemented as

cil/src/cil.ml

Lines 1429 to 1430 in bf39f60

let hasAttribute s al =
(filterAttributes s al <> [])

This is silly because filterAttributes will allocate a new list, just to check containment. This should be done with List.exists or something reasonable that doesn't allocate at all.

This showed up as a notable source of allocations while analyzing rsync. The hasAttribute is used by bitsOffset calculation (to look for packing attributes) which we heavily use in Goblint during semantic_equal of addresses (and their sets).

In addition to the one-liner change, we should evaluate the impact on rsync/sv-benchmarks.

Besides fixing this, it might make sense to also cache the bitsOffset calls on Goblint side.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@michael-schwarz It's really remarkable which places turn out to be hot when properly benchmarking. I think analyze that is worth it just for these insights already.

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
Copilot AI changed the title [WIP] Optimize hasAttribute to reduce allocations Optimize hasAttribute to avoid unnecessary list allocation Mar 19, 2026
Copilot AI requested a review from michael-schwarz March 19, 2026 01:46
Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
Copilot AI requested a review from michael-schwarz March 19, 2026 01:55
@michael-schwarz michael-schwarz requested a review from arkocal March 19, 2026 01:55
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.

Optimize hasAttribute

2 participants