Commit 82a14ca
committed
Allocate the rate and the draws together, not the rate first
Asking for both 'auto' was the most expensive thing a user could ask
for: on a 2.2+1.6 injection at the default accuracy it cost 29.6 ms a
likelihood call against 6.6 ms for a hand-picked 8192 Hz with the draws
chosen, for the same accuracy. That is backwards, and both 'auto' is what
a user will write.
The cause was the order. choose_sample_rate ran first and spent the whole
budget on the rate, since its target is 1/(vsamples*accuracy**2) with
vsamples still at its starting value; by the time the draws were sized
the budget was already met and the cheap lever had nothing left to buy.
The rate is the expensive one - the signal to noise series is rebuilt
every call, so four times the rate costs about four times as much, while
four times the draws cost tens of a percent - so it should be the lever
of last resort, not of first.
The accuracy depends only on the product of the two, which is what makes
them exchangeable. So when the number of draws is being chosen, the rate
is asked only for a resolution the product law can be trusted at and the
draws are sized to the rest of the budget. Only if the budget needs more
draws than there is room for - MOST_VSAMPLES, or the precalculated pool,
which is the real ceiling - does the rate climb, to the resolution the
most draws available would need, capped at FLOOR_RESOLVED where the rate
stops buying anything at all. That target is either reached or it is not
and the next one would be the same number, so the iteration goes round at
most twice and then says plainly that the accuracy is out of reach and
that a bigger pool, not a higher rate, is the way out.
The resolution to stop at is measured rather than picked. Sizing the
draws by the law and measuring what comes out: at one sample across the
peak the scatter is 2.8 times what was asked, at two samples - the hard
floor, where the answer stops being biased - it is still 1.5 times, and
at four samples it is 0.99 and 0.82 at two budgets a factor of four
apart. Four is where the law starts delivering what it promises, and on
this signal it is also where the total cost of a call bottoms out, since
the draws needed rise as the rate falls. Hence SANE_RESOLVED = 4.
Both 'auto' at the default accuracy now picks 8192 Hz and 13942 draws:
29.59 -> 6.14 ms a call, 4.8x cheaper, with the scatter improving from
0.0058 to 0.0053 against the 0.005 asked for. Where the draws are given
explicitly nothing changes: the rate still buys the whole budget on its
own, by the same code and with the same message.1 parent 975dc09 commit 82a14ca
2 files changed
Lines changed: 187 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
72 | 84 | | |
73 | 85 | | |
74 | 86 | | |
| |||
840 | 852 | | |
841 | 853 | | |
842 | 854 | | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
843 | 868 | | |
844 | 869 | | |
845 | 870 | | |
| |||
857 | 882 | | |
858 | 883 | | |
859 | 884 | | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
875 | 899 | | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
876 | 928 | | |
877 | 929 | | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
878 | 953 | | |
879 | 954 | | |
880 | 955 | | |
| |||
906 | 981 | | |
907 | 982 | | |
908 | 983 | | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
909 | 998 | | |
910 | 999 | | |
911 | 1000 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
307 | 308 | | |
308 | 309 | | |
309 | 310 | | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
| 311 | + | |
| 312 | + | |
320 | 313 | | |
321 | 314 | | |
322 | 315 | | |
323 | 316 | | |
324 | 317 | | |
325 | | - | |
| 318 | + | |
326 | 319 | | |
327 | 320 | | |
328 | 321 | | |
329 | 322 | | |
330 | 323 | | |
331 | 324 | | |
332 | 325 | | |
333 | | - | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
334 | 370 | | |
335 | 371 | | |
336 | 372 | | |
337 | 373 | | |
338 | 374 | | |
339 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
340 | 411 | | |
341 | 412 | | |
342 | 413 | | |
| |||
0 commit comments