Skip to content

Commit

Permalink
WIP implementation of scale using jumps
Browse files Browse the repository at this point in the history
This implementation saves the offset from the start of the cycle instead
of from the previous step, called jumps later. This favores big numerator segments as can
be seen by the benchmarks.

I decided to drop the offsets and just use the jumps
to get the offsets as the most CPU intensive part of this is calculating the jumps
Obviously this means that if most uses cases require the offsets this is not better performing

I would expect that in the cases that this gets worsen it gets worsen insignificantly
compared to the cases where the new "jumps" give much better perfomance

The sort.Search is inlined because this gives something like 30-70%
boost which I would argue here it is worth the few extra lines

name                                                                                                                  old time/op    new time/op    delta
GetStripedOffsets/length10,seed777-8                                                                                    34.5µs ±23%    25.8µs ±12%   -25.27%  (p=0.008 n=5+5)
GetStripedOffsets/length100,seed777-8                                                                                   1.65ms ±15%    1.65ms ± 8%      ~     (p=0.690 n=5+5)
GetStripedOffsetsEven/length10-8                                                                                        3.85µs ± 2%    3.75µs ± 4%      ~     (p=0.151 n=5+5)
GetStripedOffsetsEven/length100-8                                                                                       53.5µs ± 1%    50.9µs ± 1%    -4.81%  (p=0.008 n=5+5)
GetStripedOffsetsEven/length1000-8                                                                                      4.06ms ± 1%    4.05ms ± 0%      ~     (p=0.690 n=5+5)
ExecutionSegmentScale/seq:;segment:/segment.Scale(5)-8                                                                  4.41ns ±13%    4.05ns ± 8%      ~     (p=0.310 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5)-8                                                                       2.13µs ± 2%    2.10µs ± 3%      ~     (p=0.151 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5)_prefilled-8                                                             0.92ns ± 6%    0.92ns ± 7%      ~     (p=1.000 n=5+5)
ExecutionSegmentScale/seq:;segment:/segment.Scale(5523)-8                                                               4.02ns ± 3%    4.19ns ±10%      ~     (p=0.421 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5523)-8                                                                    2.24µs ± 4%    2.20µs ±15%      ~     (p=0.222 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5523)_prefilled-8                                                          0.90ns ± 9%    1.01ns ±19%      ~     (p=0.056 n=5+5)
ExecutionSegmentScale/seq:;segment:/segment.Scale(5000000)-8                                                            4.06ns ± 3%    4.32ns ± 7%      ~     (p=0.151 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5000000)-8                                                                 2.13µs ± 2%    2.17µs ± 2%      ~     (p=0.310 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5000000)_prefilled-8                                                       0.89ns ± 3%    1.00ns ± 6%   +11.41%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:/segment.Scale(67280421310721)-8                                                     4.12ns ±11%    4.26ns ±10%      ~     (p=0.310 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(67280421310721)-8                                                          2.12µs ± 2%    2.29µs ±24%      ~     (p=0.222 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(67280421310721)_prefilled-8                                                0.89ns ± 2%    1.02ns ± 5%   +14.65%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(5)-8                                                               1.76µs ±11%    1.74µs ± 2%      ~     (p=0.286 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5)-8                                                                    2.38µs ± 5%    2.33µs ± 1%      ~     (p=0.286 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5)_prefilled-8                                                          0.89ns ± 4%    0.99ns ±20%   +12.16%  (p=0.032 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(5523)-8                                                            1.69µs ± 1%    1.75µs ± 3%    +3.41%  (p=0.016 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5523)-8                                                                 2.34µs ± 2%    2.33µs ± 2%      ~     (p=0.690 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5523)_prefilled-8                                                       0.91ns ± 3%    1.00ns ±19%   +10.52%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(5000000)-8                                                         1.75µs ±12%    1.74µs ± 3%      ~     (p=0.548 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5000000)-8                                                              2.38µs ±10%    2.33µs ± 2%      ~     (p=0.690 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5000000)_prefilled-8                                                    0.87ns ± 2%    0.91ns ± 6%      ~     (p=0.151 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(67280421310721)-8                                                  1.69µs ± 2%    1.70µs ± 3%      ~     (p=0.690 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(67280421310721)-8                                                       2.33µs ± 4%    2.27µs ± 1%      ~     (p=0.111 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(67280421310721)_prefilled-8                                             0.89ns ± 3%    0.92ns ± 2%      ~     (p=0.063 n=5+4)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(5)-8                                  2.17µs ± 3%    2.20µs ± 3%      ~     (p=0.222 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5)-8                                       2.86µs ± 1%    2.82µs ± 1%    -1.11%  (p=0.048 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5)_prefilled-8                             9.90ns ± 2%    9.87ns ±11%      ~     (p=0.198 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(5523)-8                               2.06µs ± 2%    2.10µs ± 3%      ~     (p=0.310 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5523)-8                                    2.90µs ± 2%    2.87µs ± 2%      ~     (p=0.730 n=5+4)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5523)_prefilled-8                          8.71ns ± 4%    9.59ns ± 5%   +10.13%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(5000000)-8                            1.81µs ± 1%    1.82µs ± 3%      ~     (p=0.421 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5000000)-8                                 2.97µs ±11%    2.87µs ± 2%      ~     (p=0.421 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5000000)_prefilled-8                       10.2ns ± 2%    10.7ns ± 6%      ~     (p=0.087 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(67280421310721)-8                     1.96µs ± 4%    2.03µs ± 4%      ~     (p=0.095 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(67280421310721)-8                          2.88µs ± 2%    2.83µs ± 4%      ~     (p=0.310 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(67280421310721)_prefilled-8                15.1ns ± 0%    15.3ns ± 2%    +1.76%  (p=0.016 n=4+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(5)-8                      2.04µs ± 2%    2.04µs ± 2%      ~     (p=1.000 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5)-8                           3.48µs ± 1%    3.29µs ± 2%    -5.45%  (p=0.016 n=4+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5)_prefilled-8                 8.69ns ± 6%    8.32ns ± 9%      ~     (p=0.421 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(5523)-8                   1.96µs ± 2%    1.95µs ± 2%      ~     (p=0.310 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5523)-8                        3.49µs ± 4%    3.35µs ± 8%      ~     (p=0.095 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5523)_prefilled-8              9.20ns ±13%    8.31ns ± 4%      ~     (p=0.056 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(5000000)-8                1.81µs ± 2%    1.80µs ± 1%      ~     (p=0.889 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5000000)-8                     3.44µs ± 2%    3.30µs ± 5%      ~     (p=0.056 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5000000)_prefilled-8           10.1ns ± 2%    10.4ns ± 4%      ~     (p=0.111 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(67280421310721)-8         1.97µs ± 4%    1.95µs ± 2%      ~     (p=0.421 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(67280421310721)-8              3.48µs ± 2%    3.44µs ± 9%      ~     (p=0.690 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(67280421310721)_prefilled-8    15.2ns ± 2%    15.2ns ± 2%      ~     (p=0.968 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(5)-8                                                           2.64µs ± 9%    2.58µs ± 2%      ~     (p=0.841 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5)-8                                                                4.45µs ± 1%    4.46µs ± 2%      ~     (p=1.000 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5)_prefilled-8                                                      8.05ns ±12%    7.54ns ± 7%      ~     (p=0.151 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(5523)-8                                                        2.75µs ± 1%    2.76µs ± 2%      ~     (p=0.738 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5523)-8                                                             4.53µs ± 7%    4.49µs ± 6%      ~     (p=0.548 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5523)_prefilled-8                                                   9.30ns ±11%    9.48ns ±13%      ~     (p=0.421 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(5000000)-8                                                     2.56µs ± 3%    2.63µs ± 4%    +2.97%  (p=0.032 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5000000)-8                                                          4.48µs ± 3%    4.42µs ± 5%      ~     (p=0.222 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5000000)_prefilled-8                                                10.4ns ± 0%    10.5ns ± 2%      ~     (p=0.635 n=4+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(67280421310721)-8                                              2.88µs ± 2%    2.88µs ± 1%      ~     (p=1.000 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(67280421310721)-8                                                   4.47µs ± 3%    4.59µs ±11%      ~     (p=0.548 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(67280421310721)_prefilled-8                                         15.3ns ± 1%    15.1ns ± 2%      ~     (p=0.246 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(5)-8                                                     2.68µs ± 2%    2.70µs ± 4%      ~     (p=0.952 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5)-8                                                           593µs ± 1%     562µs ± 1%    -5.26%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5)_prefilled-8                                                9.82ns ± 6%   26.90ns ± 4%  +173.87%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(5523)-8                                                  2.93µs ± 6%    2.90µs ± 2%      ~     (p=0.794 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5523)-8                                                        594µs ± 1%     560µs ± 1%    -5.59%  (p=0.016 n=5+4)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5523)_prefilled-8                                             1.53µs ± 4%    0.03µs ± 3%   -98.33%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(5000000)-8                                               2.82µs ± 9%    2.76µs ± 2%      ~     (p=0.841 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5000000)-8                                                     606µs ± 2%     563µs ± 1%    -7.11%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5000000)_prefilled-8                                          5.94µs ± 2%    0.02µs ± 2%   -99.58%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(67280421310721)-8                                        3.00µs ± 1%    2.95µs ± 3%      ~     (p=0.278 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(67280421310721)-8                                              599µs ± 1%     561µs ± 0%    -6.31%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(67280421310721)_prefilled-8                                   3.68µs ± 2%    0.03µs ± 5%   -99.27%  (p=0.008 n=5+5)

name                                                                                                                  old alloc/op   new alloc/op   delta
GetStripedOffsets/length10,seed777-8                                                                                    6.42kB ±12%    5.64kB ±10%      ~     (p=0.056 n=5+5)
GetStripedOffsets/length100,seed777-8                                                                                   49.8kB ± 7%    49.3kB ± 3%      ~     (p=0.690 n=5+5)
GetStripedOffsetsEven/length10-8                                                                                        1.49kB ± 0%    1.34kB ± 0%   -10.22%  (p=0.008 n=5+5)
GetStripedOffsetsEven/length100-8                                                                                       8.93kB ± 0%    7.24kB ± 0%   -18.91%  (p=0.008 n=5+5)
GetStripedOffsetsEven/length1000-8                                                                                      74.7kB ± 0%    58.5kB ± 0%   -21.67%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:/segment.Scale(5)-8                                                                   0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/et.Scale(5)-8                                                                         624B ± 0%      608B ± 0%    -2.56%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5)_prefilled-8                                                              0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/segment.Scale(5523)-8                                                                0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/et.Scale(5523)-8                                                                      624B ± 0%      608B ± 0%    -2.56%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5523)_prefilled-8                                                           0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/segment.Scale(5000000)-8                                                             0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/et.Scale(5000000)-8                                                                   624B ± 0%      608B ± 0%    -2.56%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5000000)_prefilled-8                                                        0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/segment.Scale(67280421310721)-8                                                      0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/et.Scale(67280421310721)-8                                                            624B ± 0%      608B ± 0%    -2.56%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(67280421310721)_prefilled-8                                                 0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(5)-8                                                                 320B ± 0%      320B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5)-8                                                                      720B ± 0%      704B ± 0%    -2.22%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5)_prefilled-8                                                           0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(5523)-8                                                              320B ± 0%      320B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5523)-8                                                                   720B ± 0%      704B ± 0%    -2.22%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5523)_prefilled-8                                                        0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(5000000)-8                                                           320B ± 0%      320B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5000000)-8                                                                720B ± 0%      704B ± 0%    -2.22%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5000000)_prefilled-8                                                     0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(67280421310721)-8                                                    320B ± 0%      320B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(67280421310721)-8                                                         720B ± 0%      704B ± 0%    -2.22%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(67280421310721)_prefilled-8                                              0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(5)-8                                    424B ± 0%      424B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5)-8                                       1.06kB ± 0%    0.94kB ± 0%   -11.36%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5)_prefilled-8                              0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(5523)-8                                 424B ± 0%      424B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5523)-8                                    1.06kB ± 0%    0.94kB ± 0%   -11.36%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5523)_prefilled-8                           0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(5000000)-8                              320B ± 0%      320B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5000000)-8                                 1.06kB ± 0%    0.94kB ± 0%   -11.36%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5000000)_prefilled-8                        0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(67280421310721)-8                       376B ± 0%      376B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(67280421310721)-8                          1.06kB ± 0%    0.94kB ± 0%   -11.36%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(67280421310721)_prefilled-8                 0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(5)-8                        376B ± 0%      376B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5)-8                           1.22kB ± 0%    1.06kB ± 0%   -13.07%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5)_prefilled-8                  0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(5523)-8                     376B ± 0%      376B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5523)-8                        1.22kB ± 0%    1.06kB ± 0%   -13.07%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5523)_prefilled-8               0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(5000000)-8                  320B ± 0%      320B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5000000)-8                     1.22kB ± 0%    1.06kB ± 0%   -13.07%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5000000)_prefilled-8            0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(67280421310721)-8           376B ± 0%      376B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(67280421310721)-8              1.22kB ± 0%    1.06kB ± 0%   -13.07%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(67280421310721)_prefilled-8     0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(5)-8                                                             512B ± 0%      512B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5)-8                                                                1.49kB ± 0%    1.42kB ± 0%    -4.84%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5)_prefilled-8                                                       0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(5523)-8                                                          624B ± 0%      624B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5523)-8                                                             1.49kB ± 0%    1.42kB ± 0%    -4.84%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5523)_prefilled-8                                                    0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(5000000)-8                                                       512B ± 0%      512B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5000000)-8                                                          1.49kB ± 0%    1.42kB ± 0%    -4.84%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5000000)_prefilled-8                                                 0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(67280421310721)-8                                                672B ± 0%      672B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(67280421310721)-8                                                   1.49kB ± 0%    1.42kB ± 0%    -4.84%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(67280421310721)_prefilled-8                                          0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(5)-8                                                       568B ± 0%      568B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5)-8                                                           223kB ± 0%     223kB ± 0%    -0.01%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5)_prefilled-8                                                 0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(5523)-8                                                    672B ± 0%      672B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5523)-8                                                        223kB ± 0%     223kB ± 0%    -0.01%  (p=0.029 n=4+4)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5523)_prefilled-8                                              0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(5000000)-8                                                 568B ± 0%      568B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5000000)-8                                                     223kB ± 0%     223kB ± 0%      ~     (p=0.079 n=4+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5000000)_prefilled-8                                           0.00B          0.00B           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(67280421310721)-8                                          720B ± 0%      720B ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(67280421310721)-8                                              223kB ± 0%     223kB ± 0%    -0.01%  (p=0.000 n=4+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(67280421310721)_prefilled-8                                    0.00B          0.00B           ~     (all equal)

name                                                                                                                  old allocs/op  new allocs/op  delta
GetStripedOffsets/length10,seed777-8                                                                                      29.0 ± 0%      29.0 ± 0%      ~     (all equal)
GetStripedOffsets/length100,seed777-8                                                                                      126 ± 0%       126 ± 0%      ~     (all equal)
GetStripedOffsetsEven/length10-8                                                                                          31.0 ± 0%      31.0 ± 0%      ~     (all equal)
GetStripedOffsetsEven/length100-8                                                                                          127 ± 0%       127 ± 0%      ~     (all equal)
GetStripedOffsetsEven/length1000-8                                                                                       1.03k ± 0%     1.03k ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:/segment.Scale(5)-8                                                                    0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/et.Scale(5)-8                                                                         20.0 ± 0%      19.0 ± 0%    -5.00%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5)_prefilled-8                                                               0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/segment.Scale(5523)-8                                                                 0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/et.Scale(5523)-8                                                                      20.0 ± 0%      19.0 ± 0%    -5.00%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5523)_prefilled-8                                                            0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/segment.Scale(5000000)-8                                                              0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/et.Scale(5000000)-8                                                                   20.0 ± 0%      19.0 ± 0%    -5.00%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(5000000)_prefilled-8                                                         0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/segment.Scale(67280421310721)-8                                                       0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:/et.Scale(67280421310721)-8                                                            20.0 ± 0%      19.0 ± 0%    -5.00%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:/et.Scale(67280421310721)_prefilled-8                                                  0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(5)-8                                                                 19.0 ± 0%      19.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5)-8                                                                      22.0 ± 0%      21.0 ± 0%    -4.55%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5)_prefilled-8                                                            0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(5523)-8                                                              19.0 ± 0%      19.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5523)-8                                                                   22.0 ± 0%      21.0 ± 0%    -4.55%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5523)_prefilled-8                                                         0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(5000000)-8                                                           19.0 ± 0%      19.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5000000)-8                                                                22.0 ± 0%      21.0 ± 0%    -4.55%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(5000000)_prefilled-8                                                      0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/segment.Scale(67280421310721)-8                                                    19.0 ± 0%      19.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(67280421310721)-8                                                         22.0 ± 0%      21.0 ± 0%    -4.55%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:0:1/et.Scale(67280421310721)_prefilled-8                                               0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(5)-8                                    22.0 ± 0%      22.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5)-8                                         24.0 ± 0%      23.0 ± 0%    -4.17%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5)_prefilled-8                               0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(5523)-8                                 22.0 ± 0%      22.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5523)-8                                      24.0 ± 0%      23.0 ± 0%    -4.17%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5523)_prefilled-8                            0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(5000000)-8                              19.0 ± 0%      19.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5000000)-8                                   24.0 ± 0%      23.0 ± 0%    -4.17%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(5000000)_prefilled-8                         0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/segment.Scale(67280421310721)-8                       21.0 ± 0%      21.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(67280421310721)-8                            24.0 ± 0%      23.0 ± 0%    -4.17%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.3,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.3/et.Scale(67280421310721)_prefilled-8                  0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(5)-8                        21.0 ± 0%      21.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5)-8                             28.0 ± 0%      27.0 ± 0%    -3.57%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5)_prefilled-8                   0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(5523)-8                     21.0 ± 0%      21.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5523)-8                          28.0 ± 0%      27.0 ± 0%    -3.57%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5523)_prefilled-8                0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(5000000)-8                  19.0 ± 0%      19.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5000000)-8                       28.0 ± 0%      27.0 ± 0%    -3.57%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(5000000)_prefilled-8             0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/segment.Scale(67280421310721)-8           21.0 ± 0%      21.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(67280421310721)-8                28.0 ± 0%      27.0 ± 0%    -3.57%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1;segment:0:0.1/et.Scale(67280421310721)_prefilled-8      0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(5)-8                                                             28.0 ± 0%      28.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5)-8                                                                  41.0 ± 0%      40.0 ± 0%    -2.44%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5)_prefilled-8                                                        0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(5523)-8                                                          32.0 ± 0%      32.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5523)-8                                                               41.0 ± 0%      40.0 ± 0%    -2.44%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5523)_prefilled-8                                                     0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(5000000)-8                                                       28.0 ± 0%      28.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5000000)-8                                                            41.0 ± 0%      40.0 ± 0%    -2.44%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(5000000)_prefilled-8                                                  0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/segment.Scale(67280421310721)-8                                                33.0 ± 0%      33.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(67280421310721)-8                                                     41.0 ± 0%      40.0 ± 0%    -2.44%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2/5:4/5/et.Scale(67280421310721)_prefilled-8                                           0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(5)-8                                                       30.0 ± 0%      30.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5)-8                                                            41.0 ± 0%      40.0 ± 0%    -2.44%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5)_prefilled-8                                                  0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(5523)-8                                                    33.0 ± 0%      33.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5523)-8                                                         41.0 ± 0%      40.0 ± 0%    -2.44%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5523)_prefilled-8                                               0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(5000000)-8                                                 30.0 ± 0%      30.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5000000)-8                                                      41.0 ± 0%      40.0 ± 0%    -2.44%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(5000000)_prefilled-8                                            0.00           0.00           ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/segment.Scale(67280421310721)-8                                          34.0 ± 0%      34.0 ± 0%      ~     (all equal)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(67280421310721)-8                                               41.0 ± 0%      40.0 ± 0%    -2.44%  (p=0.008 n=5+5)
ExecutionSegmentScale/seq:;segment:2235/5213:4/5/et.Scale(67280421310721)_prefilled-8                                     0.00           0.00           ~     (all equal)
  • Loading branch information
mstoykov committed May 16, 2020
1 parent e09562d commit da02b10
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions lib/execution_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,9 @@ type ExecutionSegmentSequenceWrapper struct {
ExecutionSegmentSequence // a filled-out segment sequence
lcd int64 // pre-calculated least common denominator

// The striped offsets, i.e. the repeating indexes that "belong" to each
// The striped jumps, i.e. the repeating indexes that "belong" to each
// execution segment in the sequence.
offsets [][]int64
jumps [][]int64
}

// NewExecutionSegmentSequenceWrapper expects a filled-out execution segment
Expand All @@ -508,7 +508,7 @@ func NewExecutionSegmentSequenceWrapper(ess ExecutionSegmentSequence) *Execution
}

sequenceLength := len(ess)
offsets := make([][]int64, sequenceLength)
jumps := make([][]int64, sequenceLength)
lcd := ess.LCD()

// This will contain the normalized numerator values (i.e. what they would have
Expand All @@ -524,7 +524,7 @@ func NewExecutionSegmentSequenceWrapper(ess ExecutionSegmentSequence) *Execution
normalizedNumerator := ess[i].length.Num().Int64() * (lcd / ess[i].length.Denom().Int64())
sortedNormalizedIndexes[i].normNumerator = normalizedNumerator
sortedNormalizedIndexes[i].originalIndex = i
offsets[i] = make([]int64, 0, normalizedNumerator+1)
jumps[i] = make([]int64, 0, normalizedNumerator)
}

sort.SliceStable(sortedNormalizedIndexes, func(i, j int) bool {
Expand Down Expand Up @@ -561,28 +561,21 @@ func NewExecutionSegmentSequenceWrapper(ess ExecutionSegmentSequence) *Execution
// sorting of the segments from biggest to smallest helps with the fact that
// the biggest elements will need to take the most elements, and for them it
// will be the hardest to not get sequential elements.
prev := make([]int64, sequenceLength)
chosenCounts := make([]int64, sequenceLength)
saveIndex := func(iteration int64, index int, numerator int64) {
offsets[index] = append(offsets[index], iteration-prev[index])
prev[index] = iteration
if int64(len(offsets[index])) == numerator {
offsets[index] = append(offsets[index], offsets[index][0]+lcd-iteration)
}
}
for i := int64(0); i < lcd; i++ {
for sortedIndex, chosenCount := range chosenCounts {
num := chosenCount * lcd
denom := sortedNormalizedIndexes[sortedIndex].normNumerator
if i > num/denom || (i == num/denom && num%denom == 0) {
chosenCounts[sortedIndex]++
saveIndex(i, sortedNormalizedIndexes[sortedIndex].originalIndex, denom)
index := sortedNormalizedIndexes[sortedIndex].originalIndex
jumps[index] = append(jumps[index], i)
break
}
}
}

return &ExecutionSegmentSequenceWrapper{ExecutionSegmentSequence: ess, lcd: lcd, offsets: offsets}
return &ExecutionSegmentSequenceWrapper{ExecutionSegmentSequence: ess, lcd: lcd, jumps: jumps}
}

// LCD returns the (cached) least common denominator of the sequence - no need
Expand All @@ -593,13 +586,23 @@ func (essw *ExecutionSegmentSequenceWrapper) LCD() int64 {

// ScaleInt64 scales the provided value for the given segment.
func (essw *ExecutionSegmentSequenceWrapper) ScaleInt64(segmentIndex int, value int64) int64 {
start := essw.offsets[segmentIndex][0]
offsets := essw.offsets[segmentIndex][1:]
result := (value / essw.lcd) * int64(len(offsets))
for gi, i := 0, start; i < value%essw.lcd; gi, i = gi+1, i+offsets[gi] {
result++
jumps := essw.jumps[segmentIndex]
endValue := (value / essw.lcd) * int64(len(jumps))
remaining := value % essw.lcd
if jumps[0] <= remaining {
i, j := 0, len(jumps)
for i < j {
h := int(uint(i+j) >> 1) // avoid overflow when computing h
// i ≤ h < j
if jumps[h] < remaining {
i = h + 1 // preserves f(i-1) == false
} else {
j = h // preserves f(j) == true
}
}
endValue += int64(i)
}
return result
return endValue
}

// GetStripedOffsets returns the stripped offsets for the given segment
Expand All @@ -611,8 +614,13 @@ func (essw *ExecutionSegmentSequenceWrapper) ScaleInt64(segmentIndex int, value
// - lcd: the LCD of the lengths of all segments in the sequence. This is also the number of
// elements after which the algorithm starts to loop and give the same values
func (essw *ExecutionSegmentSequenceWrapper) GetStripedOffsets(segmentIndex int) (int64, []int64, int64) {
offsets := essw.offsets[segmentIndex]
return offsets[0], offsets[1:], essw.lcd
jumps := essw.jumps[segmentIndex]
offsets := make([]int64, len(jumps))
for i := 1; i < len(jumps); i++ {
offsets[i-1] = jumps[i] - jumps[i-1]
}
offsets[len(offsets)-1] = essw.lcd - jumps[len(jumps)-1] + jumps[0]
return jumps[0], offsets, essw.lcd
}

// GetTuple returns an ExecutionTuple for the specified segment index.
Expand Down

0 comments on commit da02b10

Please sign in to comment.