Skip to content

Rewrite and operator with #index#6

Open
yichaulin wants to merge 1 commit into
Kaligo:masterfrom
yichaulin:feature/improve_and_operator_performance
Open

Rewrite and operator with #index#6
yichaulin wants to merge 1 commit into
Kaligo:masterfrom
yichaulin:feature/improve_and_operator_performance

Conversation

@yichaulin

Copy link
Copy Markdown

Description

#index uses less allocations and has better performance than #find

Performance Benchmark

Test Suit

require 'benchmark/ips'
require "bundler/gem_tasks"
require 'json_logic'

logic = {
  "and" => [true, 1, 'a']
}


compiled = JSONLogic.compile(logic)

Benchmark.ips do |x|
  x.report("and_operator") { compiled.evaluate(nil) }

  x.compare!
end

Before PR

Warming up --------------------------------------
        and_operator   131.476k i/100ms
Calculating -------------------------------------
        and_operator      1.319M (± 0.5%) i/s -      6.705M in   5.085356s

After PR

Warming up --------------------------------------
        and_operator   145.108k i/100ms
Calculating -------------------------------------
        and_operator      1.471M (± 0.7%) i/s -      7.401M in   5.031494s

About 11% improvement

@fill32

fill32 commented May 14, 2023

Copy link
Copy Markdown

#index uses less allocations and has better performance than #find

should put the source of this insight into this PR.

About 11% improvement.

this result was from your local computer? can check this on staging also if you have time.

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.

2 participants