Home

Awesome

runiq

Build Status Crates.io

This project offers an efficient way (in both time and space) to filter duplicate entries (lines) from texual input. This project was born from neek, but optimized for both speed and memory. Several filtering options are supported depending on your data and tradeoffs you wish to make between speed and memory usage. For a more detailed explanation, see the relevant blog post.

Installation

Runiq will be available via Crates.io, so it can be installed from there directly. You can use Runiq either as a command line utility, or directly via the programmatic API.

If you wish to install Runiq as a command line utility, you can install it via an easy one-liner in your terminal:

$ cargo install runiq

If you wish to use it as a library, you can add it to your Cargo.toml as a dependency of your application:

[dependencies]
runiq = { version = "2.0", default-features = false }

You should disable the default features as it includes several dependencies which are required for the CLI use case. These dependencies are not included in your application when these features are disabled.

Examples

Below are a few examples of using the Runiq CLI to filter duplicates out of input text.

$ cat << EOF >> input.txt
this is a unique line
this is a duplicate line
this is another unique line
this is a duplicate line
this is a duplicate line
EOF

$ cat input.txt
this is a unique line
this is a duplicate line
this is another unique line
this is a duplicate line
this is a duplicate line

$ runiq input.txt
this is a unique line
this is a duplicate line
this is another unique line

For examples of the programmatic API, please see the examples.

Filters

Runiq comes with several "filters", which control exactly how uniqueness is verified. Each of these filters has different use cases, and excels in different ways.

Comparisons

To grab some rough comparisons of runiq against other methods of filtering uniques, we can use some sample data. This data is generated via Jen using the templates provided in the corresponding directory. You can create your own templates to more closely match your use case for a better comparison.

To start with, we'll generate a sample dataset of 25,000,000 JSON documents using the basic template. This template will result in an approximate 20% duplication rate (randomly dotted around the file) at this scale. Note that for longer inputs, you can tweak the rp value inside the template to cause repetition of fields.

$ jen templates/basic.tera -l 25000000 > 25000000.jsonl

File Size:     1,913,658,811 (~1.9 GB)
Total Count:      25,000,000
Unique Count:     19,832,571
Dup Offset:        5,167,429
Dup Rate:             20.67%

We can then run this sample dataset through the various filters of runiq, as well as some other tools to gauge how we're doing. These numbers are not meant to be a competition. They are simply a point of reference for myself when testing improvements. It is definitely possible that other tools might fit your data shape better.

ToolFlagsTime (Unsorted)Memory (Unsorted)Time (Sorted)Memory (Sorted)
uniqN/AN/AN/A24.9s1.6MB
sort-u380.2s8.33GB58.7s8.15GB
uqN/A22.6s2.34GB21.0s2.34GB
huniqN/A11.9s298.5MB11.6s300.7MB
runiq-f quick12.1s298.7MB11.8s298.5MB
runiq-f simple19.7s2.33GB18.2s2.33GB
runiq-f sortedN/AN/A10.3s1.3MB
runiq-f compact17.8s162.2MB16.2s162.3MB

For another point of comparison, we'll repeat these tests with a sample of 100,000,000 JSON documents (so 4x the first test). In this case, the duplicate rate will rise to approximtely 55% using the same template:

$ jen templates/basic.tera -l 100000000 > 100000000.jsonl

File Size:     7,654,658,706 (~7.7 GB)
Total Count:     100,000,000
Unique Count:     44,305,712
Dup Offset:       55,694,288
Dup Rate:             55.69%
ToolFlagsTime (Unsorted)Memory (Unsorted)Time (Sorted)Memory (Sorted)
uniqN/AN/AN/A105.8s1.6MB
sort-u2529.9s12.70GB373.0s12.42GB
uqN/A76.4s5.03GB57.9s5.03GB
huniqN/A31.2s586.3MB28.4s587.4MB
runiq-f quick34.7s586.8MB30.5s586.6MB
runiq-f simple67.4s5.00GB49.0s5.00GB
runiq-f sortedN/AN/A24.9s1.3MB
runiq-f compact66.3s338.3MB49.0s338.3M

All of these numbers are with the tool output being written to /dev/null. Some of these tools (runiq included) have flags to count/report rather than print the outputs; these use cases will always be much quicker than the numbers above.

It's also worth noting the accuracy given by the compact filter in these cases above; in both of my test sets the results were identical to those of the other filter types, showing that the compact filter is generally pretty accurate to some fairly large amounts of input (although not always!).