1. 27 9月, 2014 1 次提交
    • R
      Move object allocation out of loop · dfbcfafd
      Richard Schneeman 提交于
      Right now BenchmarkCleaner allocates hundreds of strings on every request with an exception. This patch moves those strings to be generated at boot once and re-used.
      
      ## Bench Methods
      
      I took a modified form of CodeTriage https://github.com/schneems/codetriage-ko1-test-app/blob/master/perf.rake and ran given rake tasks with and without the patch to BacktraceCleaner.
      
      I made an endpoint results in exception
      
      ```
        def index
          raise “foo"
        end
      ```
      
      The gem `memory_profiler` was used to capture objects allocated for a single request. Then `benchmark/ips` was used to test the speed of the patch.
      
      You will see that we use less objects and the code becomes measurably faster with this patch.
      
      ## With patch:
      
      Memory for one request:
      
      ```
      Total allocated 7441
      Total retained 37
      ```
      
      Requests per second:
      
      
      ```
      Calculating -------------------------------------
                       ips         4 i/100ms
      -------------------------------------------------
                       ips       43.0 (±4.7%) i/s -        216 in   5.037733s
      ```
      
      
      ## Without patch:
      
      Memory used for one request:
      
      
      ```
      Total allocated 11599
      Total retained 35 
      ```
      
      Requests per second:
      
      ```
      Calculating -------------------------------------
                       ips         3 i/100ms
      -------------------------------------------------
                       ips       39.4 (±7.6%) i/s -        198 in   5.052783s
      ```
      
      ## Analysis
      
      The patch is faster:
      
      ```
      (43.0 - 39.4 ) / 39.4 * 100
      # => 9 # % ~ speed bump
      ```
      
      It also allocates less objects:
      
      ```
      11599 - 7441
      # => 4158
      ```
      
      These strings are allocated on __EVERY SINGLE REQUEST__. This patch saves us 4158 objects __PER REQUEST__ with exception.
      
      Faster errors == Faster applications
      dfbcfafd
  2. 22 9月, 2014 4 次提交
  3. 21 9月, 2014 6 次提交
  4. 20 9月, 2014 8 次提交
  5. 19 9月, 2014 9 次提交
  6. 18 9月, 2014 12 次提交