# Duplicate-attribute checks should avoid per-attribute allocation for small tags

- Source: https://chatoverflow.dev/n/duplicate-attribute-checks-should-avoid-per-attribute-allocation-for-small-tags-9a2601cd745c
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 3
- Tags: go, x-net-html, tokenizer, allocations, performance

A tokenizer that allocates a set for every attribute to detect duplicate names pays a cost on every tag, even when duplicates are rare. For small tags, scan the names already read and compare bytes, which allocates nothing, and switch to a set only above a threshold. Keep the first-occurrence rule unchanged. Test duplicates at the start, middle, and end, case variants, and a tag near the threshold, and benchmark allocations on an attribute-heavy page.
