{"action":"created","issue":{"url":"https://api.github.com/repos/ruby-rdf/rdf/issues/213","labels_url":"https://api.github.com/repos/ruby-rdf/rdf/issues/213/labels{/name}","comments_url":"https://api.github.com/repos/ruby-rdf/rdf/issues/213/comments","events_url":"https://api.github.com/repos/ruby-rdf/rdf/issues/213/events","html_url":"https://github.com/ruby-rdf/rdf/pull/213","id":109094430,"number":213,"title":"Performance fixes","user":{"login":"jperville","id":834791,"avatar_url":"https://avatars.githubusercontent.com/u/834791?v=3","gravatar_id":"","url":"https://api.github.com/users/jperville","html_url":"https://github.com/jperville","followers_url":"https://api.github.com/users/jperville/followers","following_url":"https://api.github.com/users/jperville/following{/other_user}","gists_url":"https://api.github.com/users/jperville/gists{/gist_id}","starred_url":"https://api.github.com/users/jperville/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jperville/subscriptions","organizations_url":"https://api.github.com/users/jperville/orgs","repos_url":"https://api.github.com/users/jperville/repos","events_url":"https://api.github.com/users/jperville/events{/privacy}","received_events_url":"https://api.github.com/users/jperville/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-09-30T13:54:18Z","updated_at":"2015-10-09T20:43:28Z","closed_at":"2015-09-30T22:13:50Z","pull_request":{"url":"https://api.github.com/repos/ruby-rdf/rdf/pulls/213","html_url":"https://github.com/ruby-rdf/rdf/pull/213","diff_url":"https://github.com/ruby-rdf/rdf/pull/213.diff","patch_url":"https://github.com/ruby-rdf/rdf/pull/213.patch"},"body":"This PR contains several small performance fixes for json-ld. After merging all these fixes, a sample scenario that loads a moderate-sized json-ld file then does a lot of manipulations on it using Spira will be roughly 30% faster.\r\n\r\nIt consists in:\r\n - improvements suggested by the 'fasterer' gem (the major one was to use yield instead of `block.call` when possible; other improvements were the use of `Enumerable#flat_map` and the use of block form of `Hash#fetch` instead of using 2 argument form)\r\n - removal of useless code in the extensively-used `RDF::URI#initialize` method\r\n - use `Hash.[]` instead of `Hash#dup` when parsing options (the difference is that Hash[] does not dup the string keys of the hash, reducing the number of allocations)\r\n - refactor of the `RDF::Statement` class to use if/elsif instead of a big case when testing the different subclass cases when possible (this + reordering the clauses to avoid unneeded `Kernel.is_a?` calls made a significant difference)\r\n\r\nTo test performance, I ran the scenario for 30s with `Benchmark.ips`. The higher the numbers below the better.\r\n\r\nResults before changes:\r\n```\r\nCreateMedia.bm_create_media\r\n                          6.791  (±29.5%) i/s -    181.000 \r\n```\r\n\r\nResults after optimisations:\r\n```\r\nCreateMedia.bm_create_media\r\n                          8.597  (±11.6%) i/s -    250.000 \r\n```\r\n\r\nThere is still a lot of room for improvements, the pprof.rb graph shows that a good 20% of the execution time is spent in garbage collector."},"comment":{"url":"https://api.github.com/repos/ruby-rdf/rdf/issues/comments/146981664","html_url":"https://github.com/ruby-rdf/rdf/pull/213#issuecomment-146981664","issue_url":"https://api.github.com/repos/ruby-rdf/rdf/issues/213","id":146981664,"user":{"login":"gkellogg","id":46296,"avatar_url":"https://avatars.githubusercontent.com/u/46296?v=3","gravatar_id":"","url":"https://api.github.com/users/gkellogg","html_url":"https://github.com/gkellogg","followers_url":"https://api.github.com/users/gkellogg/followers","following_url":"https://api.github.com/users/gkellogg/following{/other_user}","gists_url":"https://api.github.com/users/gkellogg/gists{/gist_id}","starred_url":"https://api.github.com/users/gkellogg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gkellogg/subscriptions","organizations_url":"https://api.github.com/users/gkellogg/orgs","repos_url":"https://api.github.com/users/gkellogg/repos","events_url":"https://api.github.com/users/gkellogg/events{/privacy}","received_events_url":"https://api.github.com/users/gkellogg/received_events","type":"User","site_admin":false},"created_at":"2015-10-09T20:43:28Z","updated_at":"2015-10-09T20:43:28Z","body":"We're still compatible with 1.9, and will up to 2.0 for the 2.p release, can't require 2.3 yet. But, withnanduturenupdarenon the 2.2 branch, we can revert back to using yield. In the mean time, if this narrow change fixes your issue, I'll roll it into the develop branch and get a new release staged."}}