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

Add RB_UNLIKELY hint for tracing log #782

Merged
merged 1 commit into from
Jul 6, 2022
Merged

Conversation

Watson1978
Copy link
Collaborator

@Watson1978 Watson1978 commented Jul 2, 2022

I think that Yes == pi->options.trace will be false in most cases.
If the compiler supports it, the UNLIKELY hint might speed up the conditional branching slightly.

before after result
Oj.load 374.821k 383.001k 1.022x

Environment

  • Linux
    • Manjaro Linux x86_64
    • Kernel: 5.18.0-1-rt11-MANJARO
    • AMD Ryzen 7 5700G
    • gcc version 12.1.0
    • Ruby 3.1.2

Before

Warming up --------------------------------------
             Oj.load    37.784k i/100ms
Calculating -------------------------------------
             Oj.load    374.821k (± 0.5%) i/s -      7.519M in  20.060807s

After

Warming up --------------------------------------
             Oj.load    38.599k i/100ms
Calculating -------------------------------------
             Oj.load    383.001k (± 0.5%) i/s -      7.681M in  20.055707s

Test code

require 'benchmark/ips'
require 'oj'

json =<<-EOF
{
  "$id": "https://example.com/person.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "lastName": {
      "type": "string",
      "description": "The person's last name."
    },
    "age": {
      "description": "Age in years which must be equal to or greater than zero.",
      "type": "integer",
      "minimum": 0
    }
  }
}
EOF

Benchmark.ips do |x|
  x.warmup = 10
  x.time = 20

  x.report('Oj.load') { Oj.load(json) }
end

I think that `Yes == pi->options.trace` will be false in most cases.
If the compiler supports it, the UNLIKELY hint might speed up the conditional branching slightly.


−       | before   | after   | result
--       | --       | --      | --
Oj.load  | 374.821k |383.001k | 1.022x

### Environment
- Linux
  - Manjaro Linux x86_64
  - Kernel: 5.18.0-1-rt11-MANJARO 
  - AMD Ryzen 7 5700G
  - gcc version 12.1.0
  - Ruby 3.1.2

### Before
```
Warming up --------------------------------------
             Oj.load    37.784k i/100ms
Calculating -------------------------------------
             Oj.load    374.821k (± 0.5%) i/s -      7.519M in  20.060807s
```

### After
```
Warming up --------------------------------------
             Oj.load    38.599k i/100ms
Calculating -------------------------------------
             Oj.load    383.001k (± 0.5%) i/s -      7.681M in  20.055707s
```

### Test code
```ruby
require 'benchmark/ips'
require 'oj'

json =<<-EOF
{
  "$id": "https://example.com/person.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "lastName": {
      "type": "string",
      "description": "The person's last name."
    },
    "age": {
      "description": "Age in years which must be equal to or greater than zero.",
      "type": "integer",
      "minimum": 0
    }
  }
}
EOF

Benchmark.ips do |x|
  x.warmup = 10
  x.time = 20

  x.report('Oj.load') { Oj.load(json) }
end
```
@Watson1978 Watson1978 marked this pull request as draft July 2, 2022 19:22
@Watson1978 Watson1978 marked this pull request as ready for review July 2, 2022 19:22
@ohler55 ohler55 merged commit 04d9dec into ohler55:develop Jul 6, 2022
@Watson1978 Watson1978 deleted the trace branch July 7, 2022 02:06
Watson1978 added a commit to Watson1978/oj that referenced this pull request Jul 24, 2022
If the compiler supports it, the UNLIKELY hint might speed up the conditional branching slightly.
Ref. ohler55#782

−       | before  | after   | result
--       | --      | --      | --
Oj.load  | 11.754M | 11.775M | -

### Environment
- Linux
  - Manjaro Linux x86_64
  - Kernel: 5.18.12-3-MANJARO
  - AMD Ryzen 7 5700G
  - gcc version 12.1.0
  - Ruby 3.1.2

### Before
```
Warming up --------------------------------------
             Oj.dump     1.166M i/100ms
Calculating -------------------------------------
             Oj.dump     11.754M (± 0.2%) i/s -    177.254M in  15.080998s
```

### After
```
Warming up --------------------------------------
             Oj.dump     1.184M i/100ms
Calculating -------------------------------------
             Oj.dump     11.775M (± 0.2%) i/s -    177.612M in  15.084141s
```

### Test code
```ruby
require 'benchmark/ips'
require 'oj'

data = 42

Benchmark.ips do |x|
  x.warmup = 5
  x.time = 15

  x.report('Oj.dump') do |times|
    i = 0
    while i < times
      Oj.dump(data)
      i += 1
    end
  end
end
```
Watson1978 added a commit to Watson1978/oj that referenced this pull request Jul 24, 2022
If the compiler supports it, the UNLIKELY hint might speed up the conditional branching slightly.
Ref. ohler55#782

−       | before  | after   | result
--       | --      | --      | --
Oj.dump  | 11.754M | 11.775M | -

### Environment
- Linux
  - Manjaro Linux x86_64
  - Kernel: 5.18.12-3-MANJARO
  - AMD Ryzen 7 5700G
  - gcc version 12.1.0
  - Ruby 3.1.2

### Before
```
Warming up --------------------------------------
             Oj.dump     1.166M i/100ms
Calculating -------------------------------------
             Oj.dump     11.754M (± 0.2%) i/s -    177.254M in  15.080998s
```

### After
```
Warming up --------------------------------------
             Oj.dump     1.184M i/100ms
Calculating -------------------------------------
             Oj.dump     11.775M (± 0.2%) i/s -    177.612M in  15.084141s
```

### Test code
```ruby
require 'benchmark/ips'
require 'oj'

data = 42

Benchmark.ips do |x|
  x.warmup = 5
  x.time = 15

  x.report('Oj.dump') do |times|
    i = 0
    while i < times
      Oj.dump(data)
      i += 1
    end
  end
end
```
ohler55 pushed a commit that referenced this pull request Jul 24, 2022
If the compiler supports it, the UNLIKELY hint might speed up the conditional branching slightly.
Ref. #782

−       | before  | after   | result
--       | --      | --      | --
Oj.dump  | 11.754M | 11.775M | -

### Environment
- Linux
  - Manjaro Linux x86_64
  - Kernel: 5.18.12-3-MANJARO
  - AMD Ryzen 7 5700G
  - gcc version 12.1.0
  - Ruby 3.1.2

### Before
```
Warming up --------------------------------------
             Oj.dump     1.166M i/100ms
Calculating -------------------------------------
             Oj.dump     11.754M (± 0.2%) i/s -    177.254M in  15.080998s
```

### After
```
Warming up --------------------------------------
             Oj.dump     1.184M i/100ms
Calculating -------------------------------------
             Oj.dump     11.775M (± 0.2%) i/s -    177.612M in  15.084141s
```

### Test code
```ruby
require 'benchmark/ips'
require 'oj'

data = 42

Benchmark.ips do |x|
  x.warmup = 5
  x.time = 15

  x.report('Oj.dump') do |times|
    i = 0
    while i < times
      Oj.dump(data)
      i += 1
    end
  end
end
```
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