Skip to content

perf: compile BCP 47 language tag regex once at package init#341

Closed
creed-bratton wants to merge 1 commit intoitalia:mainfrom
creed-bratton:bcp47-regex-precompile
Closed

perf: compile BCP 47 language tag regex once at package init#341
creed-bratton wants to merge 1 commit intoitalia:mainfrom
creed-bratton:bcp47-regex-precompile

Conversation

@creed-bratton
Copy link
Copy Markdown
Contributor

isValidBCP47StrictLanguageTag was calling regexp.MustCompile on a complex, constant pattern on every invocation. This function runs for every key in the description map and every entry in availableLanguages, so a single parse triggers 10-50+ compilations of the same regex.

Move the regex to a package-level var so it is compiled once at program startup.

@creed-bratton creed-bratton force-pushed the bcp47-regex-precompile branch from d5de403 to 47474cb Compare March 24, 2026 18:46
creed-bratton added a commit to creed-bratton/publiccode-parser-go that referenced this pull request Apr 12, 2026
go-playground/validator@b599053 added bcp47_strict_language_tag as a
built-in validator (go-playground/validator#1489), so our copy is now
redundant. Drop validators/bcp47.go and its tests; update bcp47_keys to
delegate to the built-in tag via a package-level Validate instance.

Closes italia#341, closes italia#342.
@creed-bratton
Copy link
Copy Markdown
Contributor Author

Superseded by go-playground/validator#1489 (merged upstream). Will switch to the built-in validator in a new PR.

creed-bratton added a commit to creed-bratton/publiccode-parser-go that referenced this pull request Apr 15, 2026
go-playground/validator@b599053 added bcp47_strict_language_tag as a
built-in validator (go-playground/validator#1489), so our copy is now
redundant. Drop validators/bcp47.go and its tests; update bcp47_keys to
delegate to the built-in tag via a package-level Validate instance.

Closes italia#341, closes italia#342.
bfabio pushed a commit that referenced this pull request Apr 15, 2026
go-playground/validator@b599053 added bcp47_strict_language_tag as a
built-in validator (go-playground/validator#1489), so our copy is now
redundant. Drop validators/bcp47.go and its tests; update bcp47_keys to
delegate to the built-in tag via a package-level Validate instance.

Closes #341, closes #342.
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.

1 participant