dweiss commented on a change in pull request #2207:
URL: https://github.com/apache/lucene-solr/pull/2207#discussion_r560222284



##########
File path: 
lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/SpellChecker.java
##########
@@ -24,22 +24,24 @@
  */
 public class SpellChecker {
   private final Dictionary dictionary;
-  private final ThreadLocal<Stemmer> stemmer;
-  private final ThreadLocal<BytesRef> scratch = 
ThreadLocal.withInitial(BytesRef::new);
+  private final BytesRef scratch = new BytesRef();
 
-  public SpellChecker(Dictionary dictionary) {
+  private SpellChecker(Dictionary dictionary) {

Review comment:
       Well, I'm sorry you had problems with morfologik (which I co-wrote), but 
this is consistent with what I said - if a class doesn't say it's thread safe 
then it's very likely not... :)
   
   The way I see this is slightly different than data-structure vs. component - 
to me a dictionary is an immutable heavy data class (to load and store) and the 
rest is a mutable lightweight facade that allows convenient api over that 
immutable heavy dictionary... Even if the facade is lightweight, it's not 
really zero-cost. Creating objects is fairly cheap but when you create millions 
of them it will eventually accumulate; reusing the same buffers helps with 
caches too.
   
   Also, as for thread-safe classes... I don't think many people do it anymore 
(perhaps with the notable exception of Doug Lea :). There are typically much 
more efficient (and simpler) ways of dealing with concurrency higher up the 
stack. If you're trying to solve concurrency at such a low level you end up 
having to debug things later - for example when your thread locals keep 
references to dictionaries that are no longer used anywhere.
   
   This is all a bit philosophical and subjective, of course. There is no right 
and wrong and everyone has an unique angle of approaching things, depending of 
where they got burnt in the past. I just expressed my preference based on 
exactly that :)
   
   So it's up to you, Peter, really.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to