Skip to content

Commit

Permalink
Improve live view performance
Browse files Browse the repository at this point in the history
  * Only update hovertips/latex for new and updated cells
  * Skip the nav bar in live view. We can probably make this one incremental too
    if we really want to.
  • Loading branch information
dougalm committed Nov 16, 2023
1 parent 5b7eab4 commit add49a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/lib/Live/Web.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ serveResults resultsSubscribe request respond = do
[("Content-Type", "text/plain")] "404 - Not Found"
where
respondWith dataFname ctype = do
fname <- getDataFileName dataFname
fname <- return dataFname -- lets us skip rebuilding during development
-- fname <- getDataFileName dataFname
respond $ responseFile status200 [("Content-Type", ctype)] fname Nothing

resultStream :: ResultsServer -> StreamingBody
Expand Down
17 changes: 8 additions & 9 deletions static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function lookup_address(cell, address) {
return node
}

function renderHovertips() {
var spans = document.querySelectorAll(".code-span");
function renderHovertips(root) {
var spans = root.querySelectorAll(".code-span");
Array.from(spans).map((span) => attachHovertip(span));
}

Expand Down Expand Up @@ -63,14 +63,14 @@ function removeHighlighting(event, node) {
})
}

function renderLaTeX() {
function renderLaTeX(root) {
// Render LaTeX equations in prose blocks via KaTeX, if available.
// Skip rendering if KaTeX is unavailable.
if (typeof renderMathInElement == 'undefined') {
return;
}
// Render LaTeX equations in prose blocks via KaTeX.
var proseBlocks = document.querySelectorAll(".prose-block");
var proseBlocks = root.querySelectorAll(".prose-block");
Array.from(proseBlocks).map((proseBlock) =>
renderMathInElement(proseBlock, katexOptions)
);
Expand Down Expand Up @@ -177,8 +177,8 @@ var body = document.getElementById("main-output");
function render(renderMode) {
if (renderMode == RENDER_MODE.STATIC) {
// For static pages, simply call rendering functions once.
renderLaTeX();
renderHovertips();
renderLaTeX(document);
renderHovertips(document);
updateNavigation();
} else {
// For dynamic pages (via `dex web`), listen to update events.
Expand All @@ -191,9 +191,6 @@ function render(renderMode) {
return
} else {
process_update(msg);
renderLaTeX();
renderHovertips();
updateNavigation();
}
};
}
Expand All @@ -214,6 +211,8 @@ function set_cell_contents(cell, contents) {
} else {
console.error(tag);
}
renderLaTeX(cell);
renderHovertips(cell);
}

function process_update(msg) {
Expand Down

0 comments on commit add49a9

Please sign in to comment.