-
Notifications
You must be signed in to change notification settings - Fork 496
Load time optimization: download search index asynchronously; make cacheable #2700
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
base: master
Are you sure you want to change the base?
Changes from all commits
e8bf846
5e7c196
7da80d6
f80982f
6c98c4f
cae8623
69f530a
3cea893
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -771,7 +771,6 @@ function render(doc::Documenter.Document, settings::HTML = HTML()) | |||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
ctx = HTMLContext(doc, settings) | ||||||||||||||||||||||||||||
ctx.search_index_js = "search_index.js" | ||||||||||||||||||||||||||||
ctx.themeswap_js = copy_asset("themeswap.js", doc) | ||||||||||||||||||||||||||||
ctx.warner_js = copy_asset("warner.js", doc) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -800,9 +799,34 @@ function render(doc::Documenter.Document, settings::HTML = HTML()) | |||||||||||||||||||||||||||
copy_asset("themes/$(theme).css", doc) | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
size_limit_successes = map(collect(keys(doc.blueprint.pages))) do page | ||||||||||||||||||||||||||||
function page_navnode(page) | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bikeshed, but let's move this out of the function body perhaps. I am not a huge fan of declaring functions within functions. I think it just needs to take |
||||||||||||||||||||||||||||
idx = findfirst(nn -> nn.page == page, doc.internal.navlist) | ||||||||||||||||||||||||||||
nn = (idx === nothing) ? Documenter.NavNode(page, nothing, nothing) : doc.internal.navlist[idx] | ||||||||||||||||||||||||||||
return nn, idx | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
foreach(keys(doc.blueprint.pages)) do page | ||||||||||||||||||||||||||||
nn, idx = page_navnode(page) | ||||||||||||||||||||||||||||
@debug "Indexing $(page) [$(repr(idx))]" | ||||||||||||||||||||||||||||
generate_index!(ctx, nn) | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
Comment on lines
+808
to
+812
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmm. I don't think this works. A lot of the pushing into But yea, we have a chicken-and-egg situation here, where in order to get the full search index, we need to render everything, but we don't know how to render it because we don't know the search index hash yet, since we haven't generated the index yet. I do think that with some reorganization of the code, we could somehow generate all the DOM first, and then inject the search index file name later. Although one nice property of the current structure is that we don't need to keep the DOM of all the pages in memory at once, which I am not sure how we could keep. What I might suggest (unless you have a good simple idea of how to tackle this) is to undo the hashing related changes for now. There's also another issue with it -- MultiDocumenter, for example, relies on the |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# Make an attempt at avoiding spurious changes to the search index hash. | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be accurate?
Suggested change
|
||||||||||||||||||||||||||||
sort!(ctx.search_index; by = r -> (r.src, r.fragment, r.text)) | ||||||||||||||||||||||||||||
search_index_buf = let io = IOBuffer() | ||||||||||||||||||||||||||||
println(io, "var documenterSearchIndex = {\"docs\":") | ||||||||||||||||||||||||||||
# convert Vector{SearchRecord} to a JSON string + do additional JS escaping | ||||||||||||||||||||||||||||
println(io, JSDependencies.json_jsescape(ctx.search_index), "\n}") | ||||||||||||||||||||||||||||
take!(io) | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
# Put the index's hash in its filename so it can have a long max-age. | ||||||||||||||||||||||||||||
ctx.search_index_js = "search_index_$(dataslug(search_index_buf)).js" | ||||||||||||||||||||||||||||
open(joinpath(doc.user.build, ctx.search_index_js), "w") do io | ||||||||||||||||||||||||||||
write(io, search_index_buf) | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
size_limit_successes = map(collect(keys(doc.blueprint.pages))) do page | ||||||||||||||||||||||||||||
nn, idx = page_navnode(page) | ||||||||||||||||||||||||||||
@debug "Rendering $(page) [$(repr(idx))]" | ||||||||||||||||||||||||||||
render_page(ctx, nn) | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
@@ -837,12 +861,6 @@ function render(doc::Documenter.Document, settings::HTML = HTML()) | |||||||||||||||||||||||||||
# Check that all HTML files are smaller or equal to size_threshold option | ||||||||||||||||||||||||||||
all(size_limit_successes) || throw(HTMLSizeThresholdError()) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
open(joinpath(doc.user.build, ctx.search_index_js), "w") do io | ||||||||||||||||||||||||||||
println(io, "var documenterSearchIndex = {\"docs\":") | ||||||||||||||||||||||||||||
# convert Vector{SearchRecord} to a JSON string + do additional JS escaping | ||||||||||||||||||||||||||||
println(io, JSDependencies.json_jsescape(ctx.search_index), "\n}") | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
write_inventory(doc, ctx) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
return generate_siteinfo_json(doc.user.build) | ||||||||||||||||||||||||||||
|
@@ -1027,7 +1045,7 @@ function render_head(ctx, navnode) | |||||||||||||||||||||||||||
:src => RD.requirejs_cdn, | ||||||||||||||||||||||||||||
Symbol("data-main") => relhref(src, ctx.documenter_js), | ||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||
script[:src => relhref(src, ctx.search_index_js)], | ||||||||||||||||||||||||||||
script[:src => relhref(src, ctx.search_index_js), :async, :id => "documenter-search-index-script"], | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
script[:src => relhref(src, "siteinfo.js")], | ||||||||||||||||||||||||||||
script[:src => relhref(src, "../versions.js")], | ||||||||||||||||||||||||||||
|
@@ -1700,10 +1718,6 @@ end | |||||||||||||||||||||||||||
function domify(dctx::DCtx) | ||||||||||||||||||||||||||||
ctx, navnode = dctx.ctx, dctx.navnode | ||||||||||||||||||||||||||||
return map(getpage(ctx, navnode).mdast.children) do node | ||||||||||||||||||||||||||||
rec = searchrecord(ctx, navnode, node) | ||||||||||||||||||||||||||||
if !isnothing(rec) | ||||||||||||||||||||||||||||
push!(ctx.search_index, rec) | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
domify(dctx, node, node.element) | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
@@ -1848,6 +1862,14 @@ function domify(::DCtx, ::Node, rawnode::Documenter.RawNode) | |||||||||||||||||||||||||||
return rawnode.name === :html ? DOM.Tag(Symbol("#RAW#"))(rawnode.text) : DOM.Node[] | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
function generate_index!(ctx::HTMLContext, navnode::Documenter.NavNode) | ||||||||||||||||||||||||||||
return foreach(getpage(ctx, navnode).mdast.children) do node | ||||||||||||||||||||||||||||
rec = searchrecord(ctx, navnode, node) | ||||||||||||||||||||||||||||
if !isnothing(rec) | ||||||||||||||||||||||||||||
push!(ctx.search_index, rec) | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
Comment on lines
+1866
to
+1871
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Also, as a side note: I don't mind having |
||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# Utilities | ||||||||||||||||||||||||||||
# ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
|
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.
@xal-0 those PRs also need to be added to the list at the end of the file (make sure to pull our changes first :-) )
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.
Note: one can run
make changelog
, which will update the references inCHANGELOG.md
automatically.