-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Cache bleach.Cleaner for faster conversion of markdown to safe html #3599
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
Conversation
Avoid expensive initialization of bleach Cleaner. Saves about 3.5 seconds of processing time in the following call on tensorboard.dev: /experiment/UlN9loBoTwGczi5FlWbYEQ/data/plugin/scalars/tags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If empty descriptions were part of the problem here, maybe it's worth just adding an early exit to markdown_to_safe_html that skips the markdown conversion and bleach clean entirely and returns the empty string? That does seem like a very common case for descriptions that's worth optimizing for, since then we could potentially avoid ever initializing these objects in most request threads.
I was considering that as a next step. The change as is should considerably improve performance both for empty descriptions and non-empty descriptions. In my limited testing the early-exit-on-empty-markdown approach gains a little more performance improvement but not much. |
…ensorflow#3599) Similar to recent changes that cache Markdown instances per thread, we now cache bleach.Cleaner instances per thread. Calls to tensorboard.dev's /data/plugin/scalars/tags endpoint can be surprisingly slow if there are many tags. The following call spends ~3.5 seconds in the code that converts tag description markdown into safe html, even though the description tags are empty: http://tensorboard.dev/experiment/UlN9loBoTwGczi5FlWbYEQ/data/plugin/scalars/tags It is the call to bleach.clean() that takes up almost all of this time because it is always reinstantiating bleach.Cleaner.
…3599) Similar to recent changes that cache Markdown instances per thread, we now cache bleach.Cleaner instances per thread. Calls to tensorboard.dev's /data/plugin/scalars/tags endpoint can be surprisingly slow if there are many tags. The following call spends ~3.5 seconds in the code that converts tag description markdown into safe html, even though the description tags are empty: http://tensorboard.dev/experiment/UlN9loBoTwGczi5FlWbYEQ/data/plugin/scalars/tags It is the call to bleach.clean() that takes up almost all of this time because it is always reinstantiating bleach.Cleaner.
Calls to tensorboard.dev's /data/plugin/scalars/tags endpoint can be surprisingly slow if there are many tags.
The following call spends ~3.5 seconds in the code that converts tag description markdown into safe html, even though the description tags are empty:
http://tensorboard.dev/experiment/UlN9loBoTwGczi5FlWbYEQ/data/plugin/scalars/tags
It is the call to
bleach.clean()that takes up almost all of this time because it is always reinstantiatingbleach.Cleaner.Similar to recent changes that cache
Markdowninstances per thread, we now cachebleach.Cleanerinstances per thread.