Performance: isVoidElement creates map on every call
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
## Description
The `isVoidElement()` function creates a new map allocation on every call instead of using a package-level constant.
## Location
- `html/parser.go:131-149`
## Problem
```go
func isVoidElement(tagName string) bool {
voidElements := map[string]bool{ // Allocated every call!
"area": true,
"base": true,
// ... 14 entries
}
return voidElements[tagName]
}
```
This function is called for every start tag during HTML parsing, causing unnecessary allocations.
## Suggested Fix
Move the map to package level:
```go
var voidElements = map[string]bool{
"area": true,
"base": true,
// ...
}
func isVoidElement(tagName string) bool {
return voidElements[tagName]
}
```
## Impact
Minor but easy fix. Reduces GC pressure during HTML parsing, especially for large documents.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open html/parser.go:131-149 and inspect isVoidElement and its per-call map allocation. Move the existing void-element lookup to package scope as described, then verify that HTML parsing still recognizes the same void elements without allocating the map on each call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100