Skip to content

Avoid creating CommentMap#225

Merged
bombsimon merged 1 commit intomainfrom
less-comment-map
Jan 21, 2026
Merged

Avoid creating CommentMap#225
bombsimon merged 1 commit intomainfrom
less-comment-map

Conversation

@bombsimon
Copy link
Copy Markdown
Owner

We don't really need a CommentMap to find comments. In fact, creating a CommentMap is still iterating over all comments in a file to build it. Instead of deferring that and allocating a map, we can just iterate like this ourselves.

This will improve performance, especially in the cases where we created a CommentMap before we decided if a check was enabled and it wasn't.

This brings the default settings down on the prometheus repository from the previous average of ~4.927 (noted in #221) to ~1.852 🎉

Closes #224

We don't really need a `CommentMap` to find comments. In fact, creating
a `CommentMap` is still iterating over all comments in a file to build
it. Instead of deferring that and allocating a map, we can just iterate
like this ourselves.

This will improve performance, especially in the cases where we created
a `CommentMap` _before_ we decided if a check was enabled and it wasn't.
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 92.571% (-0.005%) from 92.576%
when pulling 1b541b7 on less-comment-map
into 456abcf on main.

@bombsimon bombsimon merged commit 6afd151 into main Jan 21, 2026
5 checks passed
@bombsimon bombsimon deleted the less-comment-map branch January 21, 2026 21:45
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.

Don't create comment map if checkLeadingNewline is disabled

2 participants