Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HTML search] optimization: don't loop over all document terms and title terms during search. #12045

Closed
jayaddison opened this issue Mar 3, 2024 · 1 comment
Labels
javascript Pull requests that update Javascript code type:performance type:proposal a feature suggestion

Comments

@jayaddison
Copy link
Contributor

Is your feature request related to a problem? Please describe.
There seems to be a potentially-large inefficiency in the Sphinx JavaScript search code: for any query word greater than length two (likely to be >90% of them, I'd guess!), we iterate through all document terms and all title terms in the client's search index to check for partial matches.

However, if an exact-match was already found on the query word, then we won't add any of those candidates, even when they do match. That means that we spend JavaScript compute resources iterating through items that are unused.

The relevant code is found here:

Object.keys(terms).forEach((term) => {
if (term.match(escapedWord) && !terms[word])
arr.push({ files: terms[term], score: Scorer.partialTerm });
});
Object.keys(titleTerms).forEach((term) => {
if (term.match(escapedWord) && !titleTerms[word])
arr.push({ files: titleTerms[word], score: Scorer.partialTitle });
});

I don't have any stats on the performance impact of this, but it feels like it may be significant, especially for large documentation projects.

Describe the solution you'd like

  • If we've already found exact-matches for a document term, then do not iterate over all document terms to check for partial matches.
  • If we've already found exact-matches for a document title term, then do not iterate over all document title terms to check for partial matches.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context

@jayaddison
Copy link
Contributor Author

Resolved by #11958.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
javascript Pull requests that update Javascript code type:performance type:proposal a feature suggestion
Projects
None yet
1 participant