Hi,

one of LT's common use cases is being run as a web service. A new 
JLanguageTool object needs to be created for every request, as it's not 
thread-safe. JLanguageTool then initializes the rules for the current 
language. Some rules need to load data from disk (lists of words etc), 
so this loading will happen for every HTTP request to the server, even 
though the data is always the same. That's a waste of CPU power.

I've now rewritten the English AvsAnRule like this: a new class 
AvsAnData reads the data once and keeps it in static fields. AvsAnRule 
accesses the data via static methods that will always return the same 
data. I see three advantages of this approach:

1) Data that doesn't change is only loaded once -> better performance, 
at least for short texts.
2) There are no static fields in the rule itself.
3) Loading the data is moved to its own class, which makes the rule 
class shorter.

You can see the simple new class which only loads and provides the data 
here:

https://github.com/languagetool-org/languagetool/blob/master/languagetool-language-modules/en/src/main/java/org/languagetool/rules/en/AvsAnData.java

If someone sees a more elegant way to improve the performance and avoid 
re-loading resources, please discuss it here. If there's no better way, 
I'm going to refactor at least all affected German and English rules to 
use the new approach described above.

Regards
  Daniel


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Languagetool-devel mailing list
Languagetool-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/languagetool-devel

Reply via email to