Commit graph

693 commits

Author SHA1 Message Date
Seebs
117942c0f3 Add stash-based implementation of Container
This implementation, controlled by the build flag "container24s",
is similar to the single-slice container implementation, but goes
a bit further. First, instead of using a native slice as its internal
storage, it uses pointer/len/cap as distinct values, and only int32
ranges for len and cap. Second, it has a small region of additional
storage which it uses as a backing store by default for arrays or
runs. The idea is that, if you request a new empty array container,
you get one with a pre-allocated virtual slice big enough for five
values, actually stored in the Container. This is useful because
Go's allocator has size classes for 16 and 32 bytes, and the
Container comes in at 24 bytes worth of storage -- meaning that if
you allocate a container, you're allocating 32 bytes anyway, so we
might as well use that space to avoid extra allocations.

This includes some test fixups because DeepEqual was testing
too much equality in some tests.

Also, we simplify unionArrayArray to postpone creating a Container
until we're ready.
2019-03-22 16:31:29 -05:00
Seebs
47dcb5b4a7 Abstract away access to container slices
On a 64-bit machine, the slices in a Container consume 72
bytes, and the Container itself is 80. But we only use one
slice at a time! This patch shifts us to keeping a single
slice in the Container, and converting provided slices to
and from that type when we want to update it. (It is not
safe to access the slice through the wrong type.)

We also add some new tests, conditional on a build tag
called `roaringparanoia`. These tests will be optimized
away entirely by the compiler when the tag isn't
present, because the conditionals use a const. These catch
possible errors like trying to access the bitmap slice
of a non-bitmap container.

We also eliminate all direct creation of Container literals,
so we can mess with the internals more. (On reflection
and study, we decided not to go to the fancier design where
references to .n and .typ were also converted to function
calls, which would have allowed packing those attributes
more tightly, because it was a lot more overhead and a lot
of work to keep track of.)

There's some circumstances where we appear to have been
relying on incorrect guesses about the nature of containers.
For instance, in xorBitmapRun, there's logic that makes sense
only if the output's a run container, but it's not, it's a
bitmap container. This creates strange behavior sometimes,
though. Several of these are corrected now.
2019-03-22 16:31:29 -05:00
Matt Jaffee
d202e6a1a0
quick fix for Bitmap.Any bug
Want to make empty containers a thing of the past, but that can wait for another
day.
2019-03-21 15:46:19 -05:00
Seebs
cf5f9f9a57 add clarifying comment 2019-03-15 11:19:49 -05:00
Seebs
97486f410b WIP: Union/UnionInPlace performance improvements
This consolidates a number of changes. The first is significant
reductions in allocation and copying during UnionInPlace
operations on very sparse containers -- for instance, combining
two array containers with one item each.

We fix up the logic for identifying and handling cases where
only one of the containers being unioned together has a given
key.

We generally favor cloning an existing container over unioning
it into a new empty container.

When unioning two containers, we were using unionIntoTargetSingle
on those two containers, into an empty bitmap. For more, we were
creating an empty bitmap, then unioning all the others into
it; it's faster to clone the first, then union the others into
it.

The overall logic for UnionInPlace is cleaned up and simplified
a bit. However, it's then complexified a bit, because it turns
out that while it's a bad idea to convert single-item arrays to
bitmaps to union them, by a few hundred items, the bitmap
conversion saves a lot of time even if it costs an allocation.

The value of N picked here is sort of arbitrary, but
512 seems to be about right. The big problem is a massive
performance hit in cases where, say, there's only a
couple of items per container, and the bitmap conversion
is extremely expensive. If you wait until N reaches
the array size cap, though, you take a very noticeable
performance hit (can be a factor of 2.5-3 in simple
testing).

We also add some stat counters, and rename an internal
method on the `handledIters` type.
2019-03-14 15:17:38 -05:00
Seebs
054cb206d5 improve union-related benchmarking
Add a benchmark to test a specific case where UnionInPlace is
underperforming the naive union operation badly.

Also, the UnionBulk test was reusing a bitmap, meaning that it ended
up doing a lot of unions into a bitmap that already had all the
bits it was supposed to have. This broke a couple of other tests
in unexpected ways.

We also now use UnionInPlace in importRoaring, and test it
in the container combinations tests via a wrapper.
2019-03-14 15:16:49 -05:00
Matt Jaffee
9fe58e5e36
exterminate unnecessary sprintf 2019-03-07 10:24:41 -06:00
Matt Jaffee
b71096b688
update licensing and NOTICE to reflect btree being moved to roaring 2019-03-05 15:52:32 -06:00
Matt Jaffee
831195e7d2
update roaring container benchmarks to do both slice and btree 2019-03-05 15:46:13 -06:00
Matt Jaffee
cfb2a80866
write large fragment import benchmark
needed to pull in btree containers to get acceptable perf building the initial
data. Still quite slow though.
2019-03-05 08:48:33 -06:00
Matt Jaffee
4c42069d5d
implements bitmap batch Direct* operations which are optimized for sorted data
also reset the data on AddN and RemoveN ops if the log write fails
2019-03-04 21:38:08 -06:00
Matt Jaffee
c32c8cda84
only write changed values to op log 2019-03-04 21:38:08 -06:00
Matt Jaffee
a58459cf0f
fix spelling of unnecessary 2019-03-04 21:38:08 -06:00
Matt Jaffee
d429d7c496
code review feedback: add Bitmap.Any and remove unecessary condition 2019-03-04 21:38:07 -06:00
Matt Jaffee
023faebd90
fix bug where opN wasn't getting set/cleared correctly 2019-03-04 21:38:07 -06:00
Matt Jaffee
04957308ba
gofmt -s 2019-03-04 21:38:07 -06:00
Matt Jaffee
ce656bbcda
factor out code to import/clear by positions 2019-03-04 21:38:07 -06:00
Matt Jaffee
537ae99fb9
add import support with aggregated op log writes 2019-03-04 21:38:07 -06:00
Matt Jaffee
67e7281a55
make sure to unmap containers before modifying 2019-02-25 17:12:27 -06:00
Todd Gruben
ffe1a285bd removed copy for pilosa roaring files 2019-02-18 16:28:37 -06:00
Travis Turner
8fe966e8a0
Modifying some of the logic around Shift()
add some comments to the shift() logic
improve test coverage
fix full bitmap overflow
add support to specify shift-by amount
2019-01-25 12:54:44 -06:00
Travis Turner
2467d88ddc
Merge branch 'master' into shift-op 2019-01-24 13:56:28 -06:00
Todd Gruben
c2ca00ebe8 force bitmap creation on test; for real this time 2019-01-23 17:05:40 -06:00
Todd Gruben
cb08749967 correct bitmap test 2019-01-23 16:47:59 -06:00
Todd Gruben
790123410f metalinter fix 2019-01-23 13:50:01 -06:00
Todd Gruben
15494becac formatting 2019-01-23 13:35:27 -06:00
Todd Gruben
374fc9deff added convience function to calculate size of bitmap in bytes
completed test converage
2019-01-23 13:30:41 -06:00
Matt Jaffee
f1ecead069
fix failing tests due to staticcheck fixes 2019-01-21 14:38:58 -06:00
Matt Jaffee
daa87d8e12
fix staticcheck warnings 2019-01-21 14:24:11 -06:00
seebs
7857730b7f
Merge branch 'master' into seebs/bench 2019-01-17 13:48:19 -06:00
tgruben
e5df52836e
Merge branch 'master' into shift-op 2019-01-15 08:57:28 -06:00
Richard Artoul
e7ca4562ea Fix bug in unionInPlaceImplementation 2018-12-12 14:26:57 -08:00
Richard Artoul
082c8aba56 switch to |= 2018-12-07 16:13:42 -05:00
Richard Artoul
dcfed6ebb6 fix grammar 2018-12-07 16:11:16 -05:00
Richard Artoul
a11d04c061 clarify comment 2018-12-07 16:11:16 -05:00
Richard Artoul
9da6d43b76 fix docstring nit 2018-12-07 16:11:16 -05:00
Richard Artoul
c495d08d1b simplify logic by removing concept or target 2018-12-07 16:11:16 -05:00
Richard Artoul
5b72544d73 simplify helper with early return 2018-12-07 16:11:16 -05:00
Richard Artoul
71621e60ba Refactor roaring repair operations 2018-12-07 16:11:16 -05:00
Richard Artoul
34b1f2199f Fix comment 2018-12-07 16:11:16 -05:00
Richard Artoul
3570ec7ab6 collapse next calls into conditonals 2018-12-07 16:11:16 -05:00
Richard Artoul
531b9d616d Refactor code and comment for clarity 2018-12-07 16:11:16 -05:00
Richard Artoul
069c2a281d unroll to make a little faster 2018-12-07 16:11:16 -05:00
Richard Artoul
c412bc595d add benchmark 2018-12-07 16:11:16 -05:00
Richard Artoul
42e756b316 Add benchmark 2018-12-07 16:11:16 -05:00
Richard Artoul
6d021fe870 add comment 2018-12-07 16:11:16 -05:00
Richard Artoul
549595cd2e fix lint issues 2018-12-07 16:11:16 -05:00
Richard Artoul
741f8e8b84 remove repairBitmaps from public iface 2018-12-07 16:11:16 -05:00
Richard Artoul
12d45415bb more refactoring and micro optimizations 2018-12-07 16:11:16 -05:00
Richard Artoul
ddfc95070b rename var 2018-12-07 16:11:16 -05:00