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

Improve speech performance, especially for lazy typesetting #1107

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Jun 20, 2024

This is the PR that we discussed today in our meeting. I have reworked the handling of the speech-generation loop using the idea I mentioned toward the end: I record the return value from the setTimeout() command and use clearTimeout() to prevent the next iteration of the loop from running if the attachSpeech() render-action is called (e.g., the page is retypeset) while there are still MathItems waiting to be processed. That turns out to be much cleaner, and you can even eliminate the attachSpeechStart() method along the way. So I think these are good changes.

Just to have it in the record, this PR:

  • Moves the Timing values to document options, where a page author can adjust them if needed.
  • Changes the setTimeout() in the KeyExplorer to a direct call to attachSeech() if there is no speech already attached.
  • Changes private to protected in case any of this needs to be subclassed.
  • Adds speechTimeout to record the value of the setTimeout() calls for the speech loop.
  • Uses that value to clear any pending loop calls if attachSpeech() is called while there are still MathItems in the awaitingSpeech array.
  • Then directly starts the loop using setTimeout().
  • Sets the process bit in attachSpeech(), indicating that the render-action has done its job (of starting the asynchronous loop). Without this, every typeset call will run attachSpeech(), even if it is not needed.
  • The loop is made into a do-while loop so that at least one MathItem will be processed (avoiding a potential infinite loop if the threshold is set too small, like 0)
  • If there are still more MathItems to process, we use setTimeout() to schedule the next loop and save the return value, otherwise, we clear the timer indicator and stop looping.
  • The lazy handler is modified to override the MathItem's attachSpeech() method so that it is not performed until we actually typeset the math.
  • We also increase the margin where the lazy loader will trigger typesetting so that we get a slightly larger head start on the speech processing.

@dpvc dpvc requested a review from zorkow June 20, 2024 19:10
@dpvc dpvc added this to the v4.0 milestone Jun 20, 2024
@dpvc
Copy link
Member Author

dpvc commented Jun 25, 2024

There is an issue with compiling the cjs version of the changes I made to the lazy handler. I will work out a fix.

@dpvc
Copy link
Member Author

dpvc commented Jun 25, 2024

Ok, I made the fix.

Copy link
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@zorkow zorkow merged commit 6e9bb8f into fix/performance_issues Jun 27, 2024
@zorkow zorkow deleted the fix/lazy-performance branch June 27, 2024 11:47
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.

2 participants