{"action":"created","issue":{"url":"https://api.github.com/repos/byroot/bootscale/issues/28","labels_url":"https://api.github.com/repos/byroot/bootscale/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/byroot/bootscale/issues/28/comments","events_url":"https://api.github.com/repos/byroot/bootscale/issues/28/events","html_url":"https://github.com/byroot/bootscale/issues/28","id":103646140,"number":28,"title":"[Possibility] Precompute cache for files without extension","user":{"login":"byroot","id":44640,"avatar_url":"https://avatars.githubusercontent.com/u/44640?v=3","gravatar_id":"","url":"https://api.github.com/users/byroot","html_url":"https://github.com/byroot","followers_url":"https://api.github.com/users/byroot/followers","following_url":"https://api.github.com/users/byroot/following{/other_user}","gists_url":"https://api.github.com/users/byroot/gists{/gist_id}","starred_url":"https://api.github.com/users/byroot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/byroot/subscriptions","organizations_url":"https://api.github.com/users/byroot/orgs","repos_url":"https://api.github.com/users/byroot/repos","events_url":"https://api.github.com/users/byroot/events{/privacy}","received_events_url":"https://api.github.com/users/byroot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-28T04:42:11Z","updated_at":"2015-08-28T16:07:40Z","closed_at":null,"body":"In a previous unreleased version I used to alias requirable files without their extension since it's the most common way to require them.\r\n\r\nFor simplicity I dropped that part.\r\n\r\n```ruby\r\nrequire 'benchmark/ips'\r\n\r\nCACHE = {'foo.rb' => '/foo.rb', 'bar.so' => '/bar.so' }\r\nOPTIMIZED = {'foo' => '/foo.rb' }\r\nLEADING_SLASH = '/'.freeze\r\nDOT_RB = '.rb'.freeze\r\nDOT_SO = '.so'.freeze\r\n\r\ndef baseline(path)\r\n  path = path.to_s\r\n  return if path.start_with?(LEADING_SLASH)\r\n  result = if path.end_with?(DOT_RB, DOT_SO)\r\n    CACHE[path]\r\n  else\r\n    CACHE[\"#{path}#{DOT_RB}\"] || CACHE[\"#{path}#{DOT_SO}\"]\r\n  end\r\n  result unless result == :relative\r\nend\r\n\r\ndef optimized(path)\r\n  path = path.to_s\r\n  return if path.start_with?(LEADING_SLASH)\r\n  result = OPTIMIZED[path]\r\n  result unless result == :relative\r\nend\r\n\r\nBenchmark.ips do |x|\r\n  x.report('baseline immediate') { baseline('foo.rb'.freeze) }\r\n  x.report('baseline 1rst') { baseline('foo'.freeze) }\r\n  x.report('baseline 2nd') { baseline('bar'.freeze) }\r\n\r\n  x.report('optimized') { optimized('foo'.freeze) }\r\nend\r\n```\r\n\r\n```\r\nCalculating -------------------------------------\r\n  baseline immediate    70.241k i/100ms\r\n       baseline 1rst    55.301k i/100ms\r\n        baseline 2nd    49.965k i/100ms\r\n           optimized    77.038k i/100ms\r\n-------------------------------------------------\r\n  baseline immediate      2.402M (± 6.5%) i/s -     12.011M\r\n       baseline 1rst      1.448M (± 5.8%) i/s -      7.244M\r\n        baseline 2nd      1.104M (± 4.8%) i/s -      5.546M\r\n           optimized      2.835M (± 6.8%) i/s -     14.175M\r\n```\r\n\r\nThe time saving is `~5ms` per 10k required files. so pretty much nothing.\r\n\r\n```ruby\r\n>> 10_000 * (1 / 550_000.0) - 10_000 * (1 / (770_380.0))\r\n=> 0.005201211208636116\r\n```\r\n\r\nBut it would realistically save 10k string allocations too, so in practice it might be interesting GC wise.\r\n\r\nThe downsize would be a bigger cache."},"comment":{"url":"https://api.github.com/repos/byroot/bootscale/issues/comments/135818003","html_url":"https://github.com/byroot/bootscale/issues/28#issuecomment-135818003","issue_url":"https://api.github.com/repos/byroot/bootscale/issues/28","id":135818003,"user":{"login":"grosser","id":11367,"avatar_url":"https://avatars.githubusercontent.com/u/11367?v=3","gravatar_id":"","url":"https://api.github.com/users/grosser","html_url":"https://github.com/grosser","followers_url":"https://api.github.com/users/grosser/followers","following_url":"https://api.github.com/users/grosser/following{/other_user}","gists_url":"https://api.github.com/users/grosser/gists{/gist_id}","starred_url":"https://api.github.com/users/grosser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grosser/subscriptions","organizations_url":"https://api.github.com/users/grosser/orgs","repos_url":"https://api.github.com/users/grosser/repos","events_url":"https://api.github.com/users/grosser/events{/privacy}","received_events_url":"https://api.github.com/users/grosser/received_events","type":"User","site_admin":false},"created_at":"2015-08-28T16:07:40Z","updated_at":"2015-08-28T16:07:40Z","body":"saving 5ms is not really worth it ... and also means more memory used that cannot be GCed ... and more moving parts / places to look stuff up ... so not a big fan"}}