Skip to content

Commit 76e83a1

Browse files
authored
Warn when the search index size is too big (#2753)
1 parent 269e5db commit 76e83a1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## Unreleased
7+
8+
### Changed
9+
10+
* Created a warning for when the search index size is too big (500Kib). ([#2423], [#2753])
11+
612
## Version [v1.14.1] - 2025-07-09
713

814
### Fixed
@@ -2051,6 +2057,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
20512057
[#2410]: https://github.com/JuliaDocs/Documenter.jl/issues/2410
20522058
[#2414]: https://github.com/JuliaDocs/Documenter.jl/issues/2414
20532059
[#2415]: https://github.com/JuliaDocs/Documenter.jl/issues/2415
2060+
[#2423]: https://github.com/JuliaDocs/Documenter.jl/issues/2423
20542061
[#2424]: https://github.com/JuliaDocs/Documenter.jl/issues/2424
20552062
[#2430]: https://github.com/JuliaDocs/Documenter.jl/issues/2430
20562063
[#2434]: https://github.com/JuliaDocs/Documenter.jl/issues/2434
@@ -2131,6 +2138,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21312138
[#2737]: https://github.com/JuliaDocs/Documenter.jl/issues/2737
21322139
[#2748]: https://github.com/JuliaDocs/Documenter.jl/issues/2748
21332140
[#2750]: https://github.com/JuliaDocs/Documenter.jl/issues/2750
2141+
[#2753]: https://github.com/JuliaDocs/Documenter.jl/issues/2753
21342142
[JuliaLang/julia#36953]: https://github.com/JuliaLang/julia/issues/36953
21352143
[JuliaLang/julia#38054]: https://github.com/JuliaLang/julia/issues/38054
21362144
[JuliaLang/julia#39841]: https://github.com/JuliaLang/julia/issues/39841

src/html/HTMLWriter.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ struct HTML <: Documenter.Writer
501501
size_threshold_warn::Int
502502
size_threshold_ignore::Vector{String}
503503
example_size_threshold::Int
504+
search_size_threshold_warn::Int
504505
inventory_version::Union{String, Nothing}
505506

506507
function HTML(;
@@ -530,6 +531,7 @@ struct HTML <: Documenter.Writer
530531
# seems reasonable, and that would lead to ~80 KiB, which is still fine
531532
# and leaves a buffer before hitting `size_threshold_warn`.
532533
example_size_threshold::Union{Integer, Nothing} = 8 * 2^10, # 8 KiB
534+
search_size_threshold_warn::Union{Integer, Nothing} = 500 * 2^10, # 500 KiB
533535
inventory_version = nothing,
534536

535537
# deprecated keywords
@@ -581,6 +583,11 @@ struct HTML <: Documenter.Writer
581583
elseif example_size_threshold < 0
582584
throw(ArgumentError("example_size_threshold must be non-negative, got $(example_size_threshold)"))
583585
end
586+
if isnothing(search_size_threshold_warn)
587+
search_size_threshold_warn = typemax(Int)
588+
elseif search_size_threshold_warn <= 0
589+
throw(ArgumentError("search_size_threshold_warn must be non-negative, got $(search_size_threshold_warn)"))
590+
end
584591
isa(edit_link, Default) && (edit_link = edit_link[])
585592
# We use normpath() when we construct the .page value for NavNodes, so we also need to normpath()
586593
# these values. This also ensures cross-platform compatibility of the values.
@@ -590,6 +597,7 @@ struct HTML <: Documenter.Writer
590597
collapselevel, sidebar_sitename, highlights, mathengine, description, footer,
591598
ansicolor, lang, warn_outdated, prerender, node, highlightjs,
592599
size_threshold, size_threshold_warn, size_threshold_ignore, example_size_threshold,
600+
search_size_threshold_warn,
593601
(isnothing(inventory_version) ? nothing : string(inventory_version))
594602
)
595603
end
@@ -861,11 +869,25 @@ function render(doc::Documenter.Document, settings::HTML = HTML())
861869
# Check that all HTML files are smaller or equal to size_threshold option
862870
all(size_limit_successes) || throw(HTMLSizeThresholdError())
863871

864-
open(joinpath(doc.user.build, ctx.search_index_js), "w") do io
872+
# Check the size of the search index
873+
search_index_path = joinpath(doc.user.build, ctx.search_index_js)
874+
open(search_index_path, "w") do io
865875
println(io, "var documenterSearchIndex = {\"docs\":")
866876
# convert Vector{SearchRecord} to a JSON string + do additional JS escaping
867877
println(io, JSDependencies.json_jsescape(ctx.search_index), "\n}")
868878
end
879+
let file_size = filesize(search_index_path)
880+
if file_size > settings.search_size_threshold_warn
881+
file_size_format_results = format_units(file_size)
882+
size_threshold_warn_format_results = format_units(settings.search_size_threshold_warn)
883+
@warn """
884+
Generated search index over size_threshold_warn limit:
885+
Generated file size: $(file_size_format_results)
886+
search_size_threshold_warn: $(size_threshold_warn_format_results)
887+
Search index file: $(search_index_path)
888+
"""
889+
end
890+
end
869891

870892
write_inventory(doc, ctx)
871893

0 commit comments

Comments
 (0)