Skip to content

Verify invariants about number of elements and length#141

Open
ameligrana wants to merge 2 commits into
mainfrom
Tortar-patch-9
Open

Verify invariants about number of elements and length#141
ameligrana wants to merge 2 commits into
mainfrom
Tortar-patch-9

Conversation

@ameligrana

Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions

github-actions Bot commented Jun 11, 2025

Copy link
Copy Markdown

Benchmark Results

3a053b9 e0935ec 3a053b9 / e0935ec
TTFX excluding time to load 0.0533 ± 0 s 0.0523 ± 0 s 1 ± 0,0.981 ± 0,1.02 ± 0
code size in bytes 1.52e+04 ± 0 h 1.52e+04 ± 0 h 1 ± 0
code size in lines 557 ± 0 h 557 ± 0 h 1 ± 0
code size in syntax nodes 4.11e+03 ± 0 h 4.11e+03 ± 0 h 1 ± 0
constructor n=100 σ=0.1 5.77 ± 0.13 μs 5.74 ± 0.24 μs 0.991 ± 0.066,1.18 ± 0.054,1.01 ± 0.048
constructor n=100 σ=1.0 6.27 ± 0.15 μs 6.24 ± 0.18 μs 0.999 ± 0.079,1.14 ± 0.055,1 ± 0.037
constructor n=100 σ=10.0 6.38 ± 0.13 μs 6.38 ± 0.13 μs 0.96 ± 0.37,1.16 ± 0.041,1 ± 0.029
constructor n=100 σ=100.0 9.83 ± 6 μs 9.49 ± 1.4 μs 0.984 ± 0.84,1.2 ± 0.18,1.04 ± 0.64
constructor n=1000 σ=0.1 0.0424 ± 0.0011 ms 0.0427 ± 0.0011 ms 0.975 ± 0.069,1.26 ± 0.045,0.994 ± 0.036
constructor n=1000 σ=1.0 0.045 ± 0.0013 ms 0.0457 ± 0.0016 ms 1 ± 0.059,1.23 ± 0.045,0.984 ± 0.045
constructor n=1000 σ=10.0 0.0517 ± 0.0011 ms 0.051 ± 0.00083 ms 0.983 ± 0.047,1.18 ± 0.028,1.01 ± 0.027
constructor n=1000 σ=100.0 0.0593 ± 0.00085 ms 0.059 ± 0.00073 ms 0.992 ± 0.058,1.17 ± 0.028,1 ± 0.019
constructor n=10000 σ=0.1 0.427 ± 0.019 ms 0.422 ± 0.022 ms 0.989 ± 0.084,1.26 ± 0.069,1.01 ± 0.069
constructor n=10000 σ=1.0 0.434 ± 0.023 ms 0.438 ± 0.017 ms 0.956 ± 0.087,1.17 ± 0.08,0.991 ± 0.065
constructor n=10000 σ=10.0 0.517 ± 0.023 ms 0.49 ± 0.027 ms 1.03 ± 0.13,1.23 ± 0.1,1.06 ± 0.074
constructor n=10000 σ=100.0 0.576 ± 0.023 ms 0.576 ± 0.025 ms 0.99 ± 0.054,1.15 ± 0.062,1 ± 0.059
delete ∘ rand n=100 σ=0.1 4.39 ± 0.2 μs 4.44 ± 0.2 μs 0.998 ± 0.062,1.38 ± 0.073,0.989 ± 0.063
delete ∘ rand n=100 σ=1.0 4.66 ± 0.21 μs 4.73 ± 0.2 μs 0.993 ± 0.061,1.3 ± 0.068,0.985 ± 0.061
delete ∘ rand n=100 σ=10.0 4.81 ± 0.19 μs 4.9 ± 0.19 μs 0.982 ± 0.054,1.3 ± 0.062,0.981 ± 0.054
delete ∘ rand n=100 σ=100.0 7.16 ± 0.47 μs 7.33 ± 0.47 μs 0.979 ± 0.088,1.28 ± 0.1,0.977 ± 0.09
delete ∘ rand n=1000 σ=0.1 0.0436 ± 0.0008 ms 0.0439 ± 0.00083 ms 0.994 ± 0.027,1.39 ± 0.03,0.995 ± 0.026
delete ∘ rand n=1000 σ=1.0 0.0473 ± 0.0012 ms 0.048 ± 0.0013 ms 0.993 ± 0.033,1.29 ± 0.034,0.986 ± 0.037
delete ∘ rand n=1000 σ=10.0 0.0484 ± 0.00099 ms 0.0493 ± 0.00099 ms 0.991 ± 0.028,1.24 ± 0.031,0.981 ± 0.028
delete ∘ rand n=1000 σ=100.0 0.0531 ± 0.001 ms 0.0543 ± 0.0011 ms 0.982 ± 0.024,1.26 ± 0.028,0.978 ± 0.027
delete ∘ rand n=10000 σ=0.1 0.474 ± 0.012 ms 0.48 ± 0.015 ms 1.09 ± 0.14,1.34 ± 0.039,0.988 ± 0.039
delete ∘ rand n=10000 σ=1.0 0.506 ± 0.014 ms 0.511 ± 0.011 ms 0.987 ± 0.043,1.25 ± 0.036,0.99 ± 0.034
delete ∘ rand n=10000 σ=10.0 0.512 ± 0.011 ms 0.523 ± 0.012 ms 0.99 ± 0.042,1.21 ± 0.042,0.978 ± 0.03
delete ∘ rand n=10000 σ=100.0 0.507 ± 0.016 ms 0.514 ± 0.013 ms 0.989 ± 0.04,1.22 ± 0.038,0.987 ± 0.04
empty constructor 1.63 ± 0.28 μs 1.76 ± 0.29 μs 0.914 ± 0.22,0.95 ± 0.24,0.926 ± 0.22
intermixed_h n=100 σ=0.1 11.1 ± 0.83 μs 11.1 ± 0.83 μs 0.995 ± 0.11,1.7 ± 0.24,0.999 ± 0.11
intermixed_h n=100 σ=1.0 11.3 ± 0.95 μs 11.4 ± 0.98 μs 1 ± 0.13,1.66 ± 0.24,0.99 ± 0.12
intermixed_h n=100 σ=10.0 11.4 ± 1.5 μs 11.3 ± 1.3 μs 0.998 ± 0.34,1.78 ± 0.49,1.01 ± 0.18
intermixed_h n=100 σ=100.0 12.1 ± 0.92 μs 12.2 ± 0.98 μs 0.998 ± 0.15,1.65 ± 0.26,0.991 ± 0.11
intermixed_h n=1000 σ=0.1 0.106 ± 0.0097 ms 0.107 ± 0.0083 ms 0.983 ± 0.12,2.06 ± 0.57,0.99 ± 0.12
intermixed_h n=1000 σ=1.0 0.109 ± 0.0082 ms 0.111 ± 0.0089 ms 0.997 ± 0.11,1.93 ± 0.59,0.987 ± 0.11
intermixed_h n=1000 σ=10.0 0.104 ± 0.0099 ms 0.104 ± 0.0091 ms 1 ± 0.13,2.05 ± 0.62,1 ± 0.13
intermixed_h n=1000 σ=100.0 0.112 ± 0.012 ms 0.113 ± 0.013 ms 0.997 ± 0.15,1.97 ± 0.57,0.999 ± 0.16
intermixed_h n=10000 σ=0.1 1.14 ± 0.19 ms 1.14 ± 0.18 ms 0.983 ± 0.2,2.1 ± 0.82,1 ± 0.23
intermixed_h n=10000 σ=1.0 1.14 ± 0.17 ms 1.15 ± 0.16 ms 0.989 ± 0.21,2.13 ± 0.92,0.985 ± 0.2
intermixed_h n=10000 σ=10.0 1.08 ± 0.15 ms 1.11 ± 0.18 ms 1.03 ± 0.21,2.15 ± 0.77,0.972 ± 0.21
intermixed_h n=10000 σ=100.0 1.12 ± 0.16 ms 1.16 ± 0.22 ms 1.02 ± 0.2,2.1 ± 0.82,0.97 ± 0.23
pathological 1 0.0456 ± 0.00025 μs 0.0456 ± 0.00019 μs 1 ± 0.0071,1.97 ± 0.21,1 ± 0.0069
pathological 1′ 0.166 ± 0.0028 μs 0.161 ± 0.0017 μs 1.05 ± 0.015,1.23 ± 0.019,1.03 ± 0.021
pathological 2 0.0629 ± 0.0002 μs 0.0629 ± 0.00019 μs 1 ± 0.0056,1.73 ± 0.11,1 ± 0.0044
pathological 2′ 0.175 ± 0.0012 μs 0.169 ± 0.0017 μs 1.04 ± 0.013,1.13 ± 0.018,1.04 ± 0.013
pathological 2′′ 0.193 ± 0.033 μs 0.189 ± 0.0064 μs 1.06 ± 0.18,1.17 ± 0.094,1.02 ± 0.18
pathological 3 16.8 ± 0.29 ns 16.9 ± 0.23 ns 0.986 ± 0.024,0.984 ± 0.019,0.993 ± 0.022
pathological 4 0.0624 ± 0.0003 μs 0.0623 ± 0.00019 μs 0.999 ± 0.006,1.68 ± 0.13,1 ± 0.0057
pathological 4′ 0.186 ± 0.0015 μs 0.205 ± 0.0016 μs 0.944 ± 0.0098,1.14 ± 0.02,0.91 ± 0.01
pathological 4′′ 0.228 ± 0.012 μs 0.237 ± 0.0057 μs 0.964 ± 0.032,1.16 ± 0.046,0.963 ± 0.058
pathological 5a 0.0446 ± 0.00018 μs 0.0446 ± 0.00014 μs 1 ± 0.0052,2.04 ± 0.25,1 ± 0.0052
pathological 5b 0.0447 ± 0.00038 μs 0.0446 ± 0.00017 μs 1 ± 0.0051,2.15 ± 0.35,1 ± 0.0094
pathological 5b′ 0.349 ± 0.0032 μs 0.328 ± 0.0037 μs 1.06 ± 0.015,1.09 ± 0.021,1.06 ± 0.015
pathological 5b′′ 0.36 ± 0.01 μs 0.344 ± 0.0068 μs 1.02 ± 0.018,1.14 ± 0.033,1.05 ± 0.036
pathological compaction 3.64 ± 0.026 ms 3.55 ± 0.068 ms 1.05 ± 0.021,1.03 ± 0.01,1.03 ± 0.021
sample (bulk) n=1000 k=10000 σ=1 0.161 ± 0.021 ms 0.163 ± 0.021 ms 0.998 ± 0.18,1.4 ± 0.18,0.985 ± 0.18
sample (bulk) n=1000 k=10000 σ=100 0.171 ± 0.039 ms 0.174 ± 0.036 ms 1 ± 0.3,0.995 ± 0.3,0.982 ± 0.3
sample (bulk) n=1000 k=1000000 σ=1 16.1 ± 2.1 ms 15.8 ± 2.1 ms 1.01 ± 0.18,1.44 ± 0.19,1.02 ± 0.19
sample (bulk) n=1000 k=1000000 σ=100 8 ± 3.1 ms 9.04 ± 4 ms 1.04 ± 0.55,1.07 ± 0.7,0.885 ± 0.53
sample (bulk) n=1000000 k=10000 σ=1 0.324 ± 0.046 ms 0.39 ± 0.023 ms 1 ± 0.14,1.13 ± 0.16,0.831 ± 0.13
sample (bulk) n=1000000 k=10000 σ=100 0.147 ± 0.028 ms 0.158 ± 0.029 ms 1 ± 0.25,1.97 ± 0.32,0.932 ± 0.25
sample (bulk) n=1000000 k=1000000 σ=1 20 ± 1.3 ms 21 ± 0.44 ms 0.977 ± 0.041,1.32 ± 0.047,0.952 ± 0.067
sample (bulk) n=1000000 k=1000000 σ=100 9.27 ± 2.7 ms 9.94 ± 2.9 ms 0.749 ± 0.22,1.02 ± 0.64,0.932 ± 0.39
sample n=100 σ=0.1 25 ± 0.65 ns 25.4 ± 0.61 ns 0.998 ± 0.04,0.991 ± 0.036,0.986 ± 0.035
sample n=100 σ=1.0 29.5 ± 2.5 ns 29.4 ± 2.3 ns 0.999 ± 0.11,0.991 ± 0.1,1 ± 0.12
sample n=100 σ=10.0 19.2 ± 4.5 ns 19.3 ± 4.8 ns 1.01 ± 0.37,1 ± 0.34,0.993 ± 0.34
sample n=100 σ=100.0 16.7 ± 3.8 ns 16.9 ± 3.7 ns 0.983 ± 0.32,0.973 ± 0.31,0.99 ± 0.31
sample n=1000 σ=0.1 23 ± 4.7 ns 26.5 ± 7.2 ns 0.998 ± 0.28,0.987 ± 0.28,0.867 ± 0.3
sample n=1000 σ=1.0 0.0319 ± 0.0023 μs 0.0321 ± 0.0021 μs 1 ± 0.11,1.01 ± 0.1,0.996 ± 0.097
sample n=1000 σ=10.0 20.3 ± 5.1 ns 20.2 ± 5.4 ns 0.99 ± 0.4,0.979 ± 0.36,1 ± 0.37
sample n=1000 σ=100.0 16.7 ± 3.7 ns 17 ± 4 ns 0.984 ± 0.33,0.978 ± 0.32,0.982 ± 0.32
sample n=10000 σ=0.1 31.5 ± 1.2 ns 0.032 ± 0.0013 μs 1.03 ± 0.18,1.01 ± 0.055,0.984 ± 0.055
sample n=10000 σ=1.0 0.0347 ± 0.0016 μs 0.0345 ± 0.0016 μs 1.01 ± 0.057,1.01 ± 0.061,1.01 ± 0.065
sample n=10000 σ=10.0 21.9 ± 6.6 ns 21.8 ± 6.3 ns 1.02 ± 0.46,0.972 ± 0.4,1 ± 0.42
sample n=10000 σ=100.0 16.8 ± 4.1 ns 17.6 ± 3.8 ns 1.05 ± 0.38,0.961 ± 0.35,0.954 ± 0.31
summarysize n=100 σ=0.1 1.13e+05 ± 0 h 1.13e+05 ± 0 h 1 ± 0
summarysize n=100 σ=1.0 1.13e+05 ± 0 h 1.13e+05 ± 0 h 1 ± 0
summarysize n=100 σ=10.0 1.13e+05 ± 0 h 1.13e+05 ± 0 h 1 ± 0
summarysize n=100 σ=100.0 1.13e+05 ± 0 h 1.13e+05 ± 0 h 1 ± 0
summarysize n=1000 σ=0.1 1.42e+05 ± 0 h 1.42e+05 ± 0 h 1 ± 0
summarysize n=1000 σ=1.0 1.42e+05 ± 0 h 1.42e+05 ± 0 h 1 ± 0
summarysize n=1000 σ=10.0 1.42e+05 ± 0 h 1.42e+05 ± 0 h 1 ± 0
summarysize n=1000 σ=100.0 1.42e+05 ± 0 h 1.42e+05 ± 0 h 1 ± 0
summarysize n=10000 σ=0.1 1e+06 ± 0 h 1e+06 ± 0 h 1 ± 0
summarysize n=10000 σ=1.0 1e+06 ± 0 h 1e+06 ± 0 h 1 ± 0
summarysize n=10000 σ=10.0 1e+06 ± 0 h 1e+06 ± 0 h 1 ± 0
summarysize n=10000 σ=100.0 1e+06 ± 0 h 1e+06 ± 0 h 1 ± 0
update ∘ rand n=100 σ=0.1 0.0821 ± 0.0021 μs 0.0844 ± 0.0022 μs 0.966 ± 0.036,1.8 ± 0.06,0.973 ± 0.036
update ∘ rand n=100 σ=1.0 0.0887 ± 0.003 μs 0.0907 ± 0.0029 μs 0.974 ± 0.045,1.67 ± 0.06,0.978 ± 0.046
update ∘ rand n=100 σ=10.0 0.0962 ± 0.0036 μs 0.0995 ± 0.0036 μs 0.967 ± 0.051,1.58 ± 0.065,0.967 ± 0.05
update ∘ rand n=100 σ=100.0 0.172 ± 0.015 μs 0.176 ± 0.015 μs 0.989 ± 0.12,1.32 ± 0.14,0.979 ± 0.12
update ∘ rand n=1000 σ=0.1 0.0826 ± 0.0022 μs 0.0852 ± 0.0023 μs 0.96 ± 0.036,1.79 ± 0.067,0.97 ± 0.037
update ∘ rand n=1000 σ=1.0 0.089 ± 0.0033 μs 0.091 ± 0.0031 μs 0.976 ± 0.048,1.67 ± 0.062,0.978 ± 0.049
update ∘ rand n=1000 σ=10.0 0.0945 ± 0.0023 μs 0.0971 ± 0.0022 μs 0.969 ± 0.028,1.59 ± 0.033,0.973 ± 0.032
update ∘ rand n=1000 σ=100.0 0.182 ± 0.0067 μs 0.187 ± 0.007 μs 0.985 ± 0.052,1.26 ± 0.067,0.976 ± 0.051
update ∘ rand n=10000 σ=0.1 0.0907 ± 0.0018 μs 0.0929 ± 0.0023 μs 0.975 ± 0.021,1.67 ± 0.029,0.977 ± 0.031
update ∘ rand n=10000 σ=1.0 0.0944 ± 0.0021 μs 0.0956 ± 0.0012 μs 1.02 ± 0.071,1.61 ± 0.041,0.988 ± 0.025
update ∘ rand n=10000 σ=10.0 0.0937 ± 0.00088 μs 0.0961 ± 0.0014 μs 0.984 ± 0.026,1.59 ± 0.037,0.974 ± 0.017
update ∘ rand n=10000 σ=100.0 0.162 ± 0.0018 μs 0.165 ± 0.002 μs 0.991 ± 0.025,1.33 ± 0.019,0.981 ± 0.016
time_to_load 0.0743 ± 0.0013 s 0.0738 ± 0.00024 s 0.987 ± 0.015,0.993 ± 0.023,1.01 ± 0.017

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

@ameligrana ameligrana changed the title Verify new invariant about number of elements Verify invariants about number of elements and length Jun 11, 2025

@LilithHafner LilithHafner left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's concerning that this PR doesn't break any tests. We should add a code path to tests that exercises resizing a ResizableWeights smaller and then performing operations including checking invariants.

Comment thread test/invariants.jl
end
end

verify_m1(m::Memory) = m[1] == _length_from_memory(length(m))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only maintain and require <=, not full ==. This allows over-allocation which is needed for repeated resizing to be performant:

Suggested change
verify_m1(m::Memory) = m[1] == _length_from_memory(length(m))
verify_m1(m::Memory) = m[1] <= _length_from_memory(length(m))

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.

2 participants