High typing latency when authoring a math-heavy note with linked preview

Steps to reproduce

  1. Download the following file. Note that it’s rather math heavy, but not overly long. (nevermind the css extension)

    example.css (4.2 KB)

  2. Copy the contents into a new Obsidian note.

  3. Open a preview of the note by Cmd+clicking. You should see both the editor and the preview at the same time.

  4. Type anything into the note. You’ll experience quite long typing latency (time between you pressing the key and the letter appearing on the screen).

Expected result

I’d expect near-zero typing latencies.

Actual result

Typing latencies around a quarter of a second.

Environment

  • Operating system: MacOS Catalina (latest dev beta)
  • Obsidian version: 0.7.1
  • Using custom CSS: Bear, but it shouldn’t matter

Additional information

I think the preview pane re-renders all of the math on every keystroke; maybe some React-style update pruning would work.

5 Likes

Uhm… we will look into it.
However, think how much lantency you have when you actually use latex? (you have to compile everytime)
or when you use Overleaf?

I tried your document and it’s doing pretty well.
What computer do you have?

I’ve also noticed severe slowdowns when editing a math heavy note and having the rendered version up side by side. I also thought the exact same thing, that the entire note was getting re-rendered on every keystroke (or something along those lines).

It’s actually not usable as it is now and I instead workaround it by editing a chunk of math and then flipping over to the rendered version to make sure that it looks correct, and then flipping back to just editing mode.

I’m not on the most powerful computer personally, it’s the 2015 12-inch MacBook. (1.1 GHz Intel Core M, 8 GB 1600 MHz DDR3, Obsidian version 0.6.7)

Uhm… we will look into it.

Thanks, @WhiteNoise!

However, think how much lantency you have when you actually use latex? (you have to compile everytime) or when you use Overleaf?

There’s more to unpack here. Firstly, Obsidian is a markdown editor, so let’s stick to its peers like Typora and VSCode for comparison. Secondly, I’m talking about typing latency (time from keystroke to the letter appearing), which is virtually nonexistent even in the LaTeX tools you mentioned.

Talking about VSCode (or any other markdown editor, for that matter), I think they traded typing latency for rendering latency; the preview doesn’t update in real time, there’s a miniature lag. I think that’s a good tradeoff — typing latency doesn’t have any place in a text editor.

I tried your document and it’s doing pretty well. What computer do you have?

Maybe it’s a Mac-specific issue? Or we have different standards? I doubt my gear is an issue (16GM RAM, i7 2.2GhZ) — and if it is, it certainly shouldn’t.

And @Alex2357, glad (and not glad) I’m not the only one having this issue! I’m of the opinion that a text editor should run on anything that is operable by a mouse — unfortunately I have to do the same workaround as you. Personally I’d prefer to have a small rendering latency rather than wait for every keystroke to appear.

Thanks. We’ll look into it.

@Eugleo: what year is your mac?

Mid 2014 15".

Thanks @WhiteNoise Just a guess, but it seems like the render method for the preview is maybe getting called on each update to the note buffer and debouncing this call could help.

3 Likes

Running into the same issue now. Dell XPS 15 9500. Closing the preview window reduces typing latency.

It looks like Obsidian uses Mathjax rather than the much faster Katex. How difficult would this be to change?

The new MathJax is on par with Katex and offers more features.

Could any of you send us a document (dropbox/gdrive) where you experience this problem the most?

2 Likes

MathJax 2 used to be slower than KaTeX, but we’re using MathJax 3, which is supposedly much faster.

We used KaTeX for Dynalist and it’s pretty good, except that it’s missing a bunch of functions and we get regular complaints about them.

Math blocks are only re-rendered when they are changed. If your file separates each block of text using 2 line breaks (1 empty line) then they should only be re-rendered when you actually modify the source block.

I’ve downloaded the provided file to do some performance testing. There seems to be 3 major sources of performance slowdowns. My PC is too fast to experience any of them, but luckily the built in debugger can impose a 4x or 6x CPU slowdown, which shows the issues clearly.

  1. HTML sanitizer is a bit slow. I’ve added a patch for this one (should be in 0.7.6), but it’s mainly slow because it re-sanitizes the whole document on edit, where it should only be re-sanitizing the edited blocks.

  2. Blocks that contain many pieces of inline LaTeX would re-render all of them on edit. For now, not much I can do about that, but we do have plans for optimization in the future. See Performance issues when working with larger .md files (With video footage)

  3. The whole document having so many separate pieces of LaTeX causes significant layout strain on the rendering engine. This one I don’t have much to help, but we do have plans for small optimizations here and there that should cut down on the performance cost of this. First optimization will remove elements that are outside of view, and second optimization will “box” panes so having a crowded preview pane won’t impact another editor pane, for example.

3 Likes

I am going to archive this as we have made significant progress in this front in 0.8.2 and 0.8.4 If you still have issues, open a specific bug report.

Was trying to find out more about this and ended up on this thread.

For others that might stumble here, here is a good comparison of Katex, Mathjax 2.x and Mathjax 3.x.. Mathjax 3 outperforms Katex both in render time and types of equations it can support.