Skip to content

Improve multi-threading performance #9

@Marcono1234

Description

@Marcono1234

Background

Current behavior:

  • LanguageDetectorBuilder defines a defaultExecutor with num-processors - 1 threads
  • LanguageDetector uses the executor per ngram size per filtered language

While this can improve the performance in some situations (e.g. when processing long texts with a large number of / all languages), it can actually decrease performance in other situations compared to running language detection in the calling thread (e.g. short texts with a small number of languages).

Change considerations

  • set an upper bound for the thread number of the default executor, or make it depent on the number of languages (or their model size / 'cost', see also below)
    For example at some point the performance improvement (if any) for a higher number of threads becomes insignificant because there is simply not enough work for them.
  • during language detection consider the following factors when deciding whether to run multi-threaded
    • number of (filtered) languages
    • length of text (respectively number of ngrams)
    • size of language model
      The number of ngrams per language differs, making the lookup more 'expensive' if there are more ngrams in the model (?).
  • refactor the code to abstract usage of CompletableFuture away, and allow more efficient single-threaded execution
    This assumes that CompletableFuture incurs overhead, even when used with r -> r.run() as exectutor (?).

However, choosing the right conditions for this might be difficult; it might even depend on the machine running the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performance-investigationIssue / pull request which is about investigating improving the performance.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions