Skip to content

no need to synchronize read-only map access#257

Open
mmimica wants to merge 1 commit intopemistahl:mainfrom
mmimica:mmimica-patch-1
Open

no need to synchronize read-only map access#257
mmimica wants to merge 1 commit intopemistahl:mainfrom
mmimica:mmimica-patch-1

Conversation

@mmimica
Copy link
Copy Markdown

@mmimica mmimica commented Jun 5, 2025

During intensive library usage (using withPreloadedLanguageModels()) I found that CPU time is mostly spent on synchonization point in com.github.pemistahl.lingua.api.LanguageDetector.Companion#loadLanguageModels.

I'm aware that the map is not thread-safe, but I believe it is not needed. The whole point of double-lock check pattern is to avoid unnecessary lock contention, and check without locking first. It is safe to lookup a EnumMap concurrently.

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