Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ erl_crash.dump
# Ignore the output of benchmarking
/bench/results

# Ignore rust lockfile since this is a library
Cargo.lock

# Rust compilation directory
target

*.iml
.idea/
target/
21 changes: 9 additions & 12 deletions bench/construction.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ end
Benchee.run(
%{
"Sorted Iterative Construction" => fn {size, _, _} ->
Enum.reduce(1..size, Discord.SortedSet.new(), &Discord.SortedSet.add(&2, &1))
:ok
Enum.reduce(1..size, SortedSet.new(), &SortedSet.add(&2, &1))
:ok
end,
"Sorted Proper Enumerable Construction" => fn {_, sorted, _} ->
Discord.SortedSet.from_proper_enumerable(sorted)
:ok
Discord.SortedSet.from_proper_enumerable(sorted)
:ok
end,
"Shuffle Enumerable Construction" => fn {_, _, shuffled} ->
Discord.SortedSet.from_enumerable(shuffled)
:ok
end,
Discord.SortedSet.from_enumerable(shuffled)
:ok
end
},
inputs: %{
"1. 5,000 Items" => make_inputs.(5000),
Expand All @@ -28,12 +28,9 @@ Benchee.run(
"6. 1,000,000 Items" => make_inputs.(1_000_000)
},
formatters: [
{Benchee.Formatters.HTML, file: "bench/results/add/html/add.html"},
Benchee.Formatters.Console
Benchee.Formatters.Console,
{Benchee.Formatters.HTML, file: "bench/results/construction/html/construction.html"}
],
save: %{
path: "bench/results/add/runs"
},
save: %{
path: "bench/results/construction/runs"
}
Expand Down
8 changes: 7 additions & 1 deletion lib/sorted_set.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ defmodule Discord.SortedSet do
|> Enum.chunk_every(bucket_size - 1)
|> Enum.reduce_while(set, fn chunk, set ->
case NifBridge.append_bucket(set, chunk) do
{:ok, :ok} ->
{:ok, :ok} ->
{:cont, set}

{:error, _} = error ->
Expand All @@ -117,6 +117,7 @@ defmodule Discord.SortedSet do
case NifBridge.add(set, item) do
{:ok, _} ->
set

other ->
other
end
Expand Down Expand Up @@ -212,6 +213,7 @@ defmodule Discord.SortedSet do
case NifBridge.size(set) do
{:ok, size} ->
size

other ->
other
end
Expand Down Expand Up @@ -322,4 +324,8 @@ defmodule Discord.SortedSet do
@spec default_bucket_size() :: pos_integer()
def default_bucket_size, do: @default_bucket_size

@doc """
Returns information about this NIF's memory allocations, as reported by jemalloc.
"""
defdelegate jemalloc_allocation_info, to: NifBridge
end
1 change: 1 addition & 0 deletions lib/sorted_set/nif_bridge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Discord.SortedSet.NifBridge do
interface.
"""
use Rustler, otp_app: :sorted_set_nif, crate: "sorted_set_nif"
use JemallocInfo.RustlerMixin

alias Discord.SortedSet
alias Discord.SortedSet.Types
Expand Down
8 changes: 4 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ defmodule SortedSet.MixProject do
defp deps do
[
{:rustler, "~> 0.22.0"},
{:jemalloc_info, "~> 0.1", app: false},
{:ex_doc, "~> 0.19", only: [:dev], runtime: false},
{:benchee, "~> 1.0", only: [:dev]},
{:benchee_html, "~> 1.0", only: [:dev]},
{:stream_data, "~> 0.4", only: [:test]},
#{:dialyxir, "~> 1.0.0-rc.3", only: [:dev], runtime: false}
{:dialyxir, "~> 1.0.0-rc.3", only: [:dev], runtime: false}
]
end

Expand All @@ -38,7 +39,7 @@ defmodule SortedSet.MixProject do
name: "SortedSet",
extras: ["README.md"],
main: "readme",
source_url: "https://github.com/discordapp/sorted_set"
source_url: "https://github.com/discord/sorted_set"
]
end

Expand All @@ -58,9 +59,8 @@ defmodule SortedSet.MixProject do
maintainers: ["Discord Core Infrastructure"],
licenses: ["MIT"],
links: %{
"GitHub" => "https://github.com/discordapp/sorted_set_nif"
"GitHub" => "https://github.com/discord/sorted_set_nif"
}
]
end

end
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"jemalloc_info": {:hex, :jemalloc_info, "0.1.0", "7a3b2a1b8bf1183ff215bcd6a8934669dc0bddbada5188bb6cfe01fe1036765a", [:mix], [], "hexpm", "39641548120a7f0ebfc6491009a68c636e5784b9e41252e9ded6f70627f2d1db"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
Expand Down
180 changes: 0 additions & 180 deletions native/sorted_set_nif/Cargo.lock

This file was deleted.

4 changes: 3 additions & 1 deletion native/sorted_set_nif/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
name = "sorted_set_nif"
version = "0.1.0"
authors = []
edition = "2018"

[lib]
name = "sorted_set_nif"
path = "src/lib.rs"
crate-type = ["cdylib"]

[dependencies]
jemalloc-info = "0.1"
jemallocator = { version = "0.3.2", features = ["disable_initial_exec_tls", "stats"] }
rustler = "0.22.0"
lazy_static = "1.0"
15 changes: 5 additions & 10 deletions native/sorted_set_nif/src/bucket.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::cmp::Ordering;
use std::ptr;
use supported_term::SupportedTerm;
use AddResult;
use AddResult::{Added, Duplicate};

use crate::supported_term::SupportedTerm;
use crate::AddResult::{self, Added, Duplicate};

#[derive(Debug, PartialEq)]
pub struct Bucket {
Expand Down Expand Up @@ -36,11 +36,7 @@ impl Bucket {
self.data.set_len(at);
other.set_len(other_len);

ptr::copy_nonoverlapping(
self.data.as_ptr().offset(at as isize),
other.as_mut_ptr(),
other.len(),
);
ptr::copy_nonoverlapping(self.data.as_ptr().add(at), other.as_mut_ptr(), other.len());
}

Bucket { data: other }
Expand Down Expand Up @@ -69,9 +65,8 @@ impl Bucket {

#[cfg(test)]
mod tests {
use bucket::Bucket;
use super::*;
use std::cmp::Ordering;
use supported_term::SupportedTerm;
use AddResult;

#[test]
Expand Down
4 changes: 2 additions & 2 deletions native/sorted_set_nif/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pub struct Configuration {

impl Default for Configuration {
fn default() -> Self {
return Self {
Self {
max_bucket_size: 200,
initial_set_capacity: 0,
};
}
}
}
Loading