Skip to content

perf: avoid invalidation-prone calls in read paths - #75

Merged
Beforerr merged 1 commit into
mainfrom
invalidation-hardening
Oct 3, 2026
Merged

Beforerr merged 1 commit into
mainfrom
invalidation-hardening

Conversation

@Beforerr

@Beforerr Beforerr commented Oct 3, 2026

Copy link
Copy Markdown
Member

Three small changes so read-path code isn't thrown away when unrelated packages load:

  • pointer on an array whose eltype isn't inferred goes through cconvert. Any package that adds a cconvert(::Type{Ptr{X}}, ::Vector) method (LibGit2 does, and it's loaded whenever Pkg is) invalidates _byte_swap!, load_attribute_data and readblock!. Calling unsafe_convert directly skips cconvert.
  • [v; x] goes through generic cat → eltype(::AbstractArray), which some packages invalidate. Replaced with push!.
  • String(::AbstractString) isn't inferred, which widened io, buffer and the constructor call in CDFDataset(filename) to Any. Added a ::String assertion.

With these, loading CDAWeb after Pkg leaves no invalidated CommonDataFormat/CDFDatasets CodeInstances (previously several hundred), and first reads of cached data no longer recompile (~0.06–0.09 s each).

`pointer` on arrays of non-inferred eltype goes through `cconvert`, which any new
`cconvert(::Type{Ptr{X}}, ::Vector)` method (LibGit2 defines one) invalidates; call
`unsafe_convert` directly. `[v; x]` goes through generic `cat` and `eltype(::AbstractArray)`;
use `push!`. `String(::AbstractString)` is not inferred, which widened the whole
`CDFDataset(filename)` body.
@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia v1)

Time benchmarks
main f03380a... main / f03380a...
elx/full_load 0.0367 ± 0.0021 ms 0.0363 ± 0.0021 ms 1.01 ± 0.083
elx/sum_array 2.5 ± 1.1 μs 2.48 ± 1.1 μs 1 ± 0.61
elx/sum_lazy 2.64 ± 0.57 μs 2.75 ± 0.65 μs 0.96 ± 0.31
elx/sum_var_access 2.25 ± 0.96 μs 2.05 ± 1.2 μs 1.09 ± 0.78
elx/var_access 0.241 ± 0.01 μs 0.241 ± 0.001 μs 1 ± 0.042
epochs/DateTime_to_TT2000 0.0622 ± 0.00029 ms 0.0652 ± 0.00024 ms 0.953 ± 0.0057
epochs/Epoch16_parse 0.309 ± 0.01 ms 0.31 ± 0.01 ms 0.996 ± 0.046
epochs/Epoch16_vs_DateTime 2.92 ± 0.011 μs 2.92 ± 0.019 μs 1 ± 0.0075
epochs/TT2000_parse 0.381 ± 0.01 ms 0.364 ± 0.01 ms 1.05 ± 0.04
epochs/TT2000_string 5.64 ± 0.26 ms 5.68 ± 0.26 ms 0.994 ± 0.064
epochs/TT2000_to_DateTime 0.112 ± 0.00037 ms 0.118 ± 0.00033 ms 0.948 ± 0.0041
epochs/TT2000_vs_DateTime 0.0525 ± 2e-05 ms 0.0556 ± 2e-05 ms 0.944 ± 0.00049
mms/full_load 21.2 ± 2.2 μs 21.2 ± 2.3 μs 0.998 ± 0.15
mms/sum_array 0.0953 ± 0.0021 s 0.0951 ± 0.0021 s 1 ± 0.031
mms/sum_slice 3.52 ± 0.43 ms 3.5 ± 0.056 ms 1.01 ± 0.13
mms/sum_var_access 3.52 ± 0.44 ms 3.49 ± 0.05 ms 1.01 ± 0.13
mms/var_access 0.09 ± 0.01 μs 0.081 ± 0.01 μs 1.11 ± 0.18
time_to_load 0.164 ± 0.0032 s 0.159 ± 0.0025 s 1.03 ± 0.026
Memory benchmarks
main f03380a... main / f03380a...
elx/full_load 0.217 k allocs: 24.8 kB 0.217 k allocs: 24.8 kB 1
elx/sum_array 12 allocs: 28 kB 12 allocs: 28 kB 1
elx/sum_lazy 12 allocs: 28 kB 12 allocs: 28 kB 1
elx/sum_var_access 14 allocs: 28.3 kB 14 allocs: 28.3 kB 1
elx/var_access 1 allocs: 0.234 kB 1 allocs: 0.234 kB 1
epochs/DateTime_to_TT2000 3 allocs: 0.0764 MB 3 allocs: 0.0764 MB 1
epochs/Epoch16_parse 3 allocs: 0.153 MB 3 allocs: 0.153 MB 1
epochs/Epoch16_vs_DateTime 0 allocs: 0 B 0 allocs: 0 B
epochs/TT2000_parse 3 allocs: 0.0764 MB 3 allocs: 0.0764 MB 1
epochs/TT2000_string 0.2 M allocs: 7.02 MB 0.2 M allocs: 7.02 MB 1
epochs/TT2000_to_DateTime 3 allocs: 0.0764 MB 3 allocs: 0.0764 MB 1
epochs/TT2000_vs_DateTime 0 allocs: 0 B 0 allocs: 0 B
mms/full_load 0.065 k allocs: 6.45 kB 0.065 k allocs: 6.45 kB 1
mms/sum_array 1.04 k allocs: 31.7 MB 1.04 k allocs: 31.7 MB 1
mms/sum_slice 0.069 k allocs: 1.29 MB 0.069 k allocs: 1.29 MB 1
mms/sum_var_access 0.069 k allocs: 1.29 MB 0.069 k allocs: 1.29 MB 1
mms/var_access 1 allocs: 0.219 kB 1 allocs: 0.219 kB 1
time_to_load 0.2 k allocs: 11.8 kB 0.2 k allocs: 11.8 kB 1

@Beforerr
Beforerr merged commit 8ffd8f8 into main Oct 3, 2026
7 checks passed
@Beforerr
Beforerr deleted the invalidation-hardening branch October 3, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant