Commit graph

108 commits

Author SHA1 Message Date
tgruben
751b7a74fe staticcheck fixes (#2278)
(cherry picked from commit 0aa5efcc51)
2022-11-15 11:33:10 -08:00
Fletcher Haynes
da9b57bd45 Updated dependency paths to reflect new repo location 2022-09-06 09:39:22 -07:00
Fletcher Haynes
eb06bb50ae Updated code to latest version for open-sourcing. 2022-09-02 13:23:39 -07:00
Pierre Fersing
e8ca41e522 Fix runCountRange when range start == interval start
When the interval is a proper superset of the range with start equal to
interval start, the range must be considered a superset or it will be
completly ignored (since it neither a subset nor it overlaps)
2020-03-13 10:47:39 +01:00
Ben Johnson
c7c9c1e1d7
v2.0.0
Co-authored-by: Cody Soyland <codysoyland@gmail.com>
2019-10-08 14:56:17 -06:00
Shaquille Wyan Que
a6ba7e339c fix container iteration bugs in roaring 2019-06-20 20:50:58 -05:00
Yuce Tekol
08f4ccb29b
Fixed conflicts; Merged with master 2019-05-31 17:16:54 +03:00
Seebs
c133ce0376 Make containers copy-on-write
This patch replaces a lot of circumstances in which containers
were being copied with circumstances in which they are shared,
using copy-on-write semantics.

To achieve this, we emulate somewhat the design of go's
native `append` function. Operations on a container may optionally
yield a new container. A container can be marked "frozen",
after which no operation should ever write to it in any way;
that applies both to the container itself and the backing store
it refers to, if any. So for instance, instead of:

	c.arrayToBitmap()

we now write:

	c = c.arrayToBitmap()

Operations which need to modify a container in any way
need to be able to return a new container, which is a modified
copy of the previous container. This applies to operations
like add/remove, but also to things like unmapping memory-mapped
storage, or changing a container's type.

Bitmaps do not support the same copy-on-write semantics,
currently, but "copying" a bitmap and sharing the containers
instead of duplicating them is *much* cheaper than copying
the containers.

Bitmaps do support a .Freeze method, which currently copies
the previous bitmap, making a new one with the same container
pointers, and freezes the individual containers. Use this
if you need a writeable copy of a bitmap -- the resulting
bitmap can safely have its set of containers modified, and
bitmap operators that would want to modify the containers
will use copy-on-write for that.

The primary motivation of this is to reduce the cost of the
row cache used by fragments. As a secondary issue, the row cache
is no longer updated on writes -- that update was actually a
race condition waiting to happen. Rather, writes to a row
invalidate the cache entry for that row. The row cache is
created by creating a new bitmap, and freezing the relevant
containers from the fragment's storage. In the case where
nothing is being written, the row cache grows to contain
bitmaps containing all those containers, but never copies
any containers. If nothing's being read, the row cache is
never created, and the containers are in general not getting
frozen. The only circumstance where copies have to happen is
when things are read (and thus stored in the row cache) and
later modified. In that case, each read freezes objects, and
the first write to a container after it's been frozen will
create a new copy.

We drop the enterprise/b btree implementation, because we
don't really need it anymore -- we now provide that
implementation by default in the open source product anyway.

Along with this, there's a lot of other changes which
improve support for nil containers, as a cheaper representation
for empty containers. Operations which we know will provide
an empty container can always short-circuit and just yield
a nil *Container. Similarly, operations which would provide
a full container can return a single shared full container
object (which is frozen). The higher-level (non type-specific)
container ops are now using that logic to short-circuit
operations for empty and full containers. (For instance,
difference of anything minus an empty container is the
original thing, union of anything and empty is the original
thing, and so on.)

The Containers interface adds "Update" and "UpdateEvery"
methods, based in part on the "Put" interface provided
by the underlying btree implementation; Update performs
a possible update in-place of a container for a given
key, bypassing the need to replicate the search for that
key in the container. UpdateEvery loops through all the
containers.

Containers do not strictly guarantee that they won't
return nil `*Container` objects. However, the container
iterators won't return those -- empty containers aren't
interesting. Some tests are updated to reflect this.

Some of the container internals, like N(), or the isArray()
and related functions, accept nil container pointers. Some,
like Thaw(), do not. For the array(), bitmap(), and runs()
methods, roaringparanoia enables an explicit panic on a nil
container explaining the problem, but the intent is that those
should never be called unless you already know you have the
right kind of container, so by default they don't perform
the extra checks. In most cases, this is already covered
because a nil container is empty, and there's no operation
we can perform that requires us to inspect the contents of
an empty container. This is passing a fair amount of testing,
but the testing may not be comprehensive enough.

The overall impact of this is pretty trivial performance-wise.
In our default roaring/ benchmarks, a few things get a few
percent faster, or slower. The advantage is that, with
read-heavy workloads, the row cache no longer eats up incredible
amounts of memory.

For a smallish test case, pilosa's memory usage (RES in top) after
startup was ~2.5GB. Without this patch, simply reading every
row a few times got memory usage to about 9GB, which seemed
reasonably stable. With this patch, memory usage went to about
3GB. This will be less noticeable in mixed read/write loads,
but it should be consistently significantly lower.

In addition to dropping things from the rowCache on modifications,
we also stopped performing a full count on a modified row when
not using a cache of a kind that would use that count, and don't
repopulate the rowCache regardless. We don't want every write
to imply a corresponding read after it.

There's a lot of room for possible future optimizations in
terms of things like in-place operations, and some of the
row/rowSegment code is a little suspicious to me, but I don't
think it should be *worse* in any cases.
2019-05-30 16:36:20 -05:00
Yuce Tekol
f15cb9e05c
added roaring min 2019-05-30 15:15:08 +03:00
Seebs
77d49ded64 so much lint
So with the switch to a new linter, we get a lot of new warnings,
and the majority of them are harmless probably, but a few might be
real. Variously just use _ to suppress warnings, or report errors.
There's probably things here that deserve better fixes, but we can
always revisit it.
2019-04-16 12:07:18 -05:00
Matt Jaffee
836b467d3d
add support to modify shard width at build time
use "make <x> SHARD_WIDTH=nn"

fix tests to run and pass at different shardwidths

add shardwidth22 test to circle ci
2019-04-04 13:46:26 -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
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
831195e7d2
update roaring container benchmarks to do both slice and btree 2019-03-05 15:46:13 -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
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
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
seebs
7857730b7f
Merge branch 'master' into seebs/bench 2019-01-17 13:48:19 -06:00
Richard Artoul
e7ca4562ea Fix bug in unionInPlaceImplementation 2018-12-12 14:26:57 -08:00
Richard Artoul
25eae0204d Update benchmarks 2018-12-07 16:11:16 -05:00
Richard Artoul
339a78d88d wokring 2018-12-07 16:11:15 -05:00
Richard Artoul
e8e4369f76 all passing 2018-12-07 16:11:15 -05:00
Richard Artoul
30946a0372 working 2018-12-07 16:11:15 -05:00
Richard Artoul
d2da91fdde add test 2018-12-07 16:11:15 -05:00
Seebs
67e3dc4a08 roaring: improve SliceAscending/SliceDescending tests
Two changes: First, make SliceDescending set the entire
slice, not all-but-one bits. Second, add tests that are
"striped", so it's writing to 8 parts of the slice
sequentially, rather than just going up or down the whole
thing, because that gives us some cheap indication of
cache-locality impact, which turns out to be possibly
significant.
2018-11-26 14:12:02 -06:00
Seebs
7c82f48046 improve testing for intersections of array/array pairs
A transient bug introduced in intersectionCountArrayArray was
not caught by the tests, because it would only manifest when
two containers of different lengths were being compared. Also
improve the testing for intersectArrayArray, even though that
code hasn't been changed.
2018-11-16 15:00:09 -06:00
Seebs
c8e6fd2e43 improve type matrix for IntersectionCount benchmarks
The circumstances under which bitmaps are converted between
types are not 100% nailed down, and the IntersectionCount
benchmark was actually using a bitmap for the "run" data set
as well as for the "bitmap" data set. Fix that by using
Optimize() explicitly. Also, add a second RLE set so we
can compare the difference between "one run for the entire
set" and "several runs".

Also add array/array comparisons. We use two different
lengths of arrays, because performance turns out to vary
between "first array longer" and "second array longer".

Also added a benchmark for getBenchData itself, since it's
at least one possible use case for "creating a lot of
containers".
2018-11-16 14:59:09 -06:00
Yuce Tekol
37fdd73a7f
DirectAdd adds a single value 2018-09-17 17:16:03 +03:00
Yuce Tekol
09c24cd3be
Changed the signature of Bitmap.DirectAdd function 2018-09-17 17:10:02 +03:00
Yuce Tekol
266051dd26
Adds DirectAdd function to roaring.Bitmap 2018-09-17 16:25:34 +03:00
Travis Turner
5dd7a9556a
rename slice to shard 2018-06-28 14:07:07 -05:00
Matt Jaffee
61fcf99f3e
unexport bitmapsEqual 2018-05-15 15:53:26 -05:00
Cody Soyland
5103bfd8ce Remove errant "z". 2018-05-15 11:34:47 -05:00
Cody Soyland
e8fcb0f055 Use NewFileBitmap for tests to test btree/slice containers separately. 2018-05-15 11:22:19 -05:00
Cody Soyland
faa79a385c Add B+tree to enterprise subpackage 2018-05-11 20:20:24 -05:00
Cody Soyland
2590b25628 Merge branch 'master' into vendor-btree 2018-05-10 11:28:13 -05:00
Ilias Dimos
13e3b04443 Fix misspells in comments 2018-03-09 14:12:15 +02:00
Matt Jaffee
26b6f6b119
rename NewBitmap to NewSliceBitmap 2018-02-07 13:56:58 -06:00
Todd Gruben
23970b98dc
changed roaring.NewBitmapBTree to roaring.NewBTreeBitmap 2018-02-07 13:56:58 -06:00
Todd Gruben
440980384c
applied travis suggestions 2018-02-07 13:56:58 -06:00
Todd Gruben
8a70c4e5a3
added slice containers type for in memory bitmaps and btree for file based 2018-02-07 13:56:58 -06:00
Matthew Jaffee
d798963798
fix a bunch of bugs and add some tests 2018-02-07 13:56:56 -06:00
Todd Gruben
1dbe64da3c made sure Linear and Reverse delt with same bits 2017-12-19 10:45:27 -06:00
Todd Gruben
d0d6d3d6b6 added benchmarks for runs for intersect count 2017-12-19 07:52:53 -06:00
Todd Gruben
4ceaed5316 missed one 2017-12-19 07:21:24 -06:00
Todd Gruben
0f3d26bd30 addressed jaffee suggestions; tweaked parameters 2017-12-19 07:15:40 -06:00
Todd Gruben
ccf57e23cd removed overlap calc 2017-12-18 15:33:22 -06:00