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

Drop support of symbol hash keys #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

imrefoldeskaligo
Copy link

@imrefoldeskaligo imrefoldeskaligo commented Jan 10, 2023

Summary

Handling dynamic conversion between String and Symbol keys creates a significant perfomance bottleneck. With this change, if data is passed as Hash, keys need to be provided as String. As a result, we can expect ~30% performance improvement.

Test Suite

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


data = { 'a' => 1, 'b' => { 'c' => 2, 'd' => 3 } }
logic = { 'var' => 'b.c' }

compiled = JSONLogic.compile(logic)

Benchmark.ips do |x|
  x.report("apply-compiled-logic") { compiled.evaluate(data) }
  x.compare!
end

Before PR

Warming up --------------------------------------
apply-compiled-logic    59.924k i/100ms
Calculating -------------------------------------
apply-compiled-logic    603.481k (± 1.4%) i/s -      3.056M in   5.065220s

After PR

Warming up --------------------------------------
apply-compiled-logic    79.318k i/100ms
Calculating -------------------------------------
apply-compiled-logic    799.975k (± 2.5%) i/s -      4.045M in   5.059387s

Base automatically changed from feature/logic-compiler to master February 21, 2023 10:03
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.

1 participant