Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove nif #10

Merged
merged 2 commits into from
Jun 1, 2024
Merged

Remove nif #10

merged 2 commits into from
Jun 1, 2024

Conversation

NelsonVides
Copy link
Collaborator

@NelsonVides NelsonVides commented May 29, 2024

🙂

Name           ips        average  deviation         median         99th %
new         4.04 M        0.25 μs  ±4922.09%        0.21 μs        0.38 μs
old         0.60 M        1.66 μs   ±514.31%        1.63 μs        2.08 μs

Comparison: 
new         4.04 M
old         0.60 M - 6.69x slower +1.41 μs

Memory usage statistics:

Name    Memory usage
new            152 B
old            408 B - 2.68x memory usage +256 B

For the record, it is also faster in OTP26:

Operating System: macOS
CPU Information: Apple M3 Pro
Number of Available Cores: 12
Available memory: 36 GB
Elixir 1.16.3
Erlang 26.2.5
JIT enabled: true

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 5 s
reduction time: 0 ns
parallel: 1
inputs: uuid
Estimated total run time: 24 s

Benchmarking new with input uuid ...
Benchmarking old with input uuid ...    
Calculating statistics...
Formatting results...

##### With input uuid #####
Name           ips        average  deviation         median         99th %
new         3.68 M        0.27 μs  ±5946.21%        0.25 μs        0.38 μs
old         0.53 M        1.90 μs   ±479.67%        1.83 μs        2.42 μs

Comparison: 
new         3.68 M
old         0.53 M - 7.01x slower +1.63 μs

Memory usage statistics:

Name    Memory usage
new            152 B
old            352 B - 2.32x memory usage +200 B

**All measurements for memory usage were the same**

On a RaspberryPi equivalent:

Compiling 1 file (-ex)
Generated benchs app
Operating System: Linux
CPU Information: ARMv8 Processor rev 4 (v81)
Number of Available Cores: 6
Available memory: 3.70 GB
Elixir 1.16.3
Erlang 26.2.5
JIT enabled: true
Benchmark suite executing with the following configuration: warmup: 2 s time: 5 s
memory time: 5 s reduction time: 0 ns parallel: 1 inputs: uuid
Estimated total run time: 24 s
Benchmarking new with input uuid Benchmarking old with input uuid
Calculating statistics...
Formatting results...
##### With input uuid #####
Name           ips        average  deviation         median         99th %
new         654.12 K        1.53 ms  ±983.47%        1.38 ms        2.33 ms
old         134.76 K       17.42 ms   ±311.80%        7.17 ms        8.50 ms

Comparison: 
new         654.12 K
old         134.76 K - 4.85x slower +5.89 ms

Memory usage statistics:

Name    Memory usage
new            152 B
old            360 B - 2.32x memory usage +208 B

Copy link

@michal-stx michal-stx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting. Is this because of JIT or some other changes in the beam?

@NelsonVides
Copy link
Collaborator Author

That's interesting. Is this because of JIT or some other changes in the beam?

Lots of optimisations in binary matching, as well as type-based optimisations that allow the JIT to generate much better code. This algorithm is so so simple that the cost of calling a NIF makes a difference against the run of the actual NIF too 😄

According to benchee, for this commit:
Operating System: macOS
CPU Information: Apple M3 Pro
Number of Available Cores: 12
Available memory: 36 GB
Elixir 1.17.0-rc.0
Erlang 27.0
JIT enabled: true

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 5 s
reduction time: 0 ns
parallel: 1
inputs: uuid
Estimated total run time: 24 s

Benchmarking new with input uuid ...
Benchmarking old with input uuid ...
Calculating statistics...
Formatting results...

Name           ips        average  deviation         median         99th %
new         3.96 M      252.38 ns  ±6313.75%         250 ns         375 ns
old         1.46 M      684.58 ns  ±2412.42%         625 ns         875 ns

Comparison:
new         3.96 M
old         1.46 M - 2.71x slower +432.20 ns

Memory usage statistics:

Name    Memory usage
new         0.148 KB
old          3.54 KB - 23.84x memory usage +3.39 KB

According to this and the previous commit, that is, these optimisations
against master with nifs:
Name           ips        average  deviation         median         99th %
new         4.04 M        0.25 μs  ±4922.09%        0.21 μs        0.38 μs
old         0.60 M        1.66 μs   ±514.31%        1.63 μs        2.08 μs

Comparison:
new         4.04 M
old         0.60 M - 6.69x slower +1.41 μs

Memory usage statistics:

Name    Memory usage
new            152 B
old            408 B - 2.68x memory usage +256 B
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 93.33333% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 85.10%. Comparing base (3d70277) to head (80c1dcc).

Files Patch % Lines
src/jid.erl 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #10      +/-   ##
==========================================
+ Coverage   84.09%   85.10%   +1.01%     
==========================================
  Files           1        1              
  Lines          88       94       +6     
==========================================
+ Hits           74       80       +6     
  Misses         14       14              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@DenysGonchar DenysGonchar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job

Copy link
Contributor

@DenysGonchar DenysGonchar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's run tests on amd64 before merging it.

@NelsonVides
Copy link
Collaborator Author

Let's run tests on amd64 before merging it.

Results in a x86 Linux machine are satisfactory:

OTP 26

Operating System: Linux
CPU Information: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Number of Available Cores: 12
Available memory: 30.97 GB
Elixir 1.16.3
Erlang 26.2.5
JIT enabled: true

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 5 s
reduction time: 0 ns
parallel: 1
inputs: uuid
Estimated total run time: 24 s

Benchmarking new with input uuid ...
Benchmarking old with input uuid ...
Calculating statistics...
Formatting results...

##### With input uuid #####
Name           ips        average  deviation         median         99th %
new         1.62 M        0.62 μs  ±5248.72%        0.51 μs        1.14 μs
old         0.35 M        2.87 μs   ±552.30%        2.60 μs        5.80 μs

Comparison: 
new         1.62 M
old         0.35 M - 4.65x slower +2.25 μs

Memory usage statistics:

Name    Memory usage
new            152 B
old            360 B - 2.37x memory usage +208 B

**All measurements for memory usage were the same**

And OTP 27:

Operating System: Linux
CPU Information: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Number of Available Cores: 12
Available memory: 30.97 GB
Elixir 1.17.0-rc.0
Erlang 27.0
JIT enabled: true

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 5 s
reduction time: 0 ns
parallel: 1
inputs: uuid
Estimated total run time: 24 s

Benchmarking new with input uuid ...
Benchmarking old with input uuid ...
Calculating statistics...
Formatting results...

##### With input uuid #####
Name           ips        average  deviation         median         99th %
new         1.68 M        0.60 μs  ±4852.13%        0.46 μs        1.85 μs
old         0.34 M        2.95 μs   ±664.60%        2.71 μs        5.34 μs

Comparison: 
new         1.68 M
old         0.34 M - 4.95x slower +2.35 μs

Memory usage statistics:

Name    Memory usage
new            152 B
old            408 B - 2.68x memory usage +256 B

**All measurements for memory usage were the same**

@DenysGonchar DenysGonchar merged commit 14c5242 into master Jun 1, 2024
3 checks passed
@NelsonVides NelsonVides deleted the remove_nif branch June 2, 2024 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants