Skip to content

Commit 397006a

Browse files
committed
Full bundling for small slider spaces
1 parent d8f3a97 commit 397006a

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

src/Actions.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ function process(
7171
!is_glob_match(path, settings.SliderServer.exclude)
7272
skip_cache =
7373
keep_running ||
74-
is_glob_match(path, settings.Export.ignore_cache) ||
75-
path settings.Export.ignore_cache
74+
is_glob_match(path, settings.Export.ignore_cache)
7675

7776
cached_state = skip_cache ? nothing : try_fromcache(settings.Export.cache_dir, new_hash)
7877

@@ -136,6 +135,7 @@ function process(
136135
output_dir,
137136
)
138137
# TODO shutdown
138+
# TODO cache
139139
end
140140

141141
@info "### ✓ $(progress) Ready" s.path new_hash

src/Configuration.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ end
3232
"List of notebook files to skip precomputation. Provide paths relative to `start_dir`."
3333
exclude::Vector{String} = String[]
3434
max_filesize_per_group::Integer = 1_000_000
35+
36+
"Combines multiple bind state precomputations into a single file"
37+
bundling_enabled::Bool = false
38+
"Maximum filesize of a full bundle including all group bond updates. Since these files are sent in full over the internet, their size must be small"
39+
max_full_bundle_size::Integer = 500_000
3540
end
3641

3742
@extract_docs @option struct ExportSettings

src/precomputed/index.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ function generate_precomputed_staterequests(
130130
connections = run.bond_connections
131131
current_hash = sesh.current_hash
132132

133+
should_bundle = settings.Precompute.bundling_enabled
134+
133135
@assert run isa RunningNotebook
134136

135137
mkpath(joinpath(output_dir, "bondconnections"))
138+
mkpath(joinpath(output_dir, "bundles"))
136139
mkpath(joinpath(output_dir, "staterequest", URIs.escapeuri(current_hash)))
140+
mkpath(joinpath(output_dir, "staterequest-bundled", URIs.escapeuri(current_hash)))
137141

138142
bondconnections_path =
139143
joinpath(output_dir, "bondconnections", URIs.escapeuri(current_hash))
@@ -156,8 +160,12 @@ function generate_precomputed_staterequests(
156160
@warn "Notebook cannot be (fully) precomputed" report
157161
end
158162

163+
bundle_index = String[]
159164
foreach(groups) do group::VariableGroupPossibilities
160165
if group.judgement.should_precompute_all
166+
should_bundle_group = should_bundle && group.judgement.can_fully_bundle
167+
168+
bundle = Dict{String,Any}()
161169
for (combination, bonds_dict) in combination_iterator(group)
162170
filename = Pluto.pack(bonds_dict) |> base64urlencode
163171
if length(filename) > 255
@@ -176,10 +184,32 @@ function generate_precomputed_staterequests(
176184

177185
write(write_path, Pluto.pack(result))
178186

187+
if should_bundle_group
188+
bundle[filename] = result
189+
end
190+
179191
@debug "Written state request to " write_path values =
180192
(; (zip(group.names, combination))...)
181193
end
182194
end
195+
196+
if should_bundle_group
197+
bundle_signature = Pluto.pack(sort(group.names)) |> base64urlencode
198+
push!(bundle_index, bundle_signature)
199+
bundle_path = joinpath(
200+
output_dir,
201+
"staterequest-bundled",
202+
URIs.escapeuri(current_hash),
203+
bundle_signature,
204+
)
205+
write(bundle_path, Pluto.pack(bundle))
206+
207+
@debug "Written bundled states to " bundle_path bundle_signature
208+
end
183209
end
184210
end
211+
write(
212+
joinpath(output_dir, "bundles", URIs.escapeuri(current_hash)),
213+
Pluto.pack(bundle_index),
214+
)
185215
end

src/precomputed/types.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const Reason = Symbol
1111

1212
Base.@kwdef struct Judgement
1313
should_precompute_all::Bool = false
14+
can_fully_bundle::Bool = false
1415
not_available::Bool = false
1516
close_to_filesize_limit::Bool = false
1617
exceeds_filesize_limit::Bool = false
@@ -42,17 +43,21 @@ function VariableGroupPossibilities(;
4243
@assert settings isa PlutoDeploySettings
4344

4445
limit = settings.Precompute.max_filesize_per_group
46+
bundle_limit = settings.Precompute.max_full_bundle_size
4547
current = mean(file_size_sample_distribution)
4648

4749
exceeds_filesize_limit = current > limit
50+
exceeds_bundle_size_limit = current > bundle_limit
4851
close_to_filesize_limit = current > limit * 0.7
4952
else
50-
exceeds_filesize_limit = close_to_filesize_limit = false
53+
54+
exceeds_filesize_limit = exceeds_bundle_size_limit = close_to_filesize_limit = false
55+
5156
end
5257

5358
j = Judgement(;
5459
should_precompute_all=!is_not_available && !exceeds_filesize_limit,
55-
exceeds_filesize_limit,
60+
can_fully_bundle=!exceeds_bundle_size_limit,
5661
close_to_filesize_limit,
5762
not_available=is_not_available,
5863
)
@@ -203,9 +208,15 @@ sum_distributions(ds; init=Normal(0, 0)) =
203208
any(isnothing, ds) ? nothing : reduce(convolve, ds; init=init)
204209

205210

206-
pretty(j::Judgement) =
207-
if j.should_precompute_all
211+
pretty(j::Judgement) = begin
212+
s = ""
213+
s *= if j.should_precompute_all
208214
j.close_to_filesize_limit ? "⚠️" : ""
209215
else
210216
""
211217
end
218+
if j.can_fully_bundle
219+
s *= " 📦"
220+
end
221+
s
222+
end

0 commit comments

Comments
 (0)