{"action":"created","issue":{"url":"https://api.github.com/repos/WP-API/WP-API/issues/2558","repository_url":"https://api.github.com/repos/WP-API/WP-API","labels_url":"https://api.github.com/repos/WP-API/WP-API/issues/2558/labels{/name}","comments_url":"https://api.github.com/repos/WP-API/WP-API/issues/2558/comments","events_url":"https://api.github.com/repos/WP-API/WP-API/issues/2558/events","html_url":"https://github.com/WP-API/WP-API/issues/2558","id":162333453,"number":2558,"title":"Increasing per_page scales poorly due to WP_REST_Posts_Controller::get_item_schema calls","user":{"login":"27pchrisl","id":6286310,"avatar_url":"https://avatars.githubusercontent.com/u/6286310?v=3","gravatar_id":"","url":"https://api.github.com/users/27pchrisl","html_url":"https://github.com/27pchrisl","followers_url":"https://api.github.com/users/27pchrisl/followers","following_url":"https://api.github.com/users/27pchrisl/following{/other_user}","gists_url":"https://api.github.com/users/27pchrisl/gists{/gist_id}","starred_url":"https://api.github.com/users/27pchrisl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/27pchrisl/subscriptions","organizations_url":"https://api.github.com/users/27pchrisl/orgs","repos_url":"https://api.github.com/users/27pchrisl/repos","events_url":"https://api.github.com/users/27pchrisl/events{/privacy}","received_events_url":"https://api.github.com/users/27pchrisl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-26T15:50:44Z","updated_at":"2016-06-26T16:07:34Z","closed_at":null,"body":"Hi,\r\n\r\nWhilst profiling our application, I found that as you increase per_page on a posts request there is a subsequent rise in get_item_schema calls. These calls are quite intensive (particularly if there is extra schema being added in a custom post type).\r\n\r\nHere are some stats from kcachegrind showing that the inclusive cost of get_item_schema() calls trends upwards without caching, but with caching the inclusive cost is lower, and trends sharply downwards as per_page increases. The effect of caching is also significant increase in the speed of the overall HTTP request.\r\n\r\n```\r\nwithout schema caching:\r\nper_page incl  self  called (overall time to run 5x http requests as reported by curl)\r\n10       24.74 6.67  278    (3.577)\r\n20       31.15 8.65  528    (5.701)\r\n30       33.23 9.51  778    (7.199)\r\n40       34.70 10.61 1028   (8.671)\r\n100      37.85 10.80 2528   (18.925)\r\n\r\nwith schema caching:\r\nper_page incl self called (overall time to run 5x http requests as reported by curl)\r\n10       2.57 0.22 278    (2.899)\r\n20       1.39 0.18 528    (3.946)\r\n30       0.87 0.13 778    (4.887)\r\n40       0.17 0.10 1028   (6.239)\r\n100      0.28 0.04 2538   (12.072)\r\n```\r\n\r\nHere is the code that did the caching from a subclass:\r\n\r\n```\r\n  private $schema;\r\n  public function get_item_schema() {\r\n    if ($this->schema) {\r\n      return $this->schema;\r\n    }\r\n\r\n    $this->schema = parent::get_item_schema();\r\n    return $this->schema;\r\n  }\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/WP-API/WP-API/issues/comments/228608580","html_url":"https://github.com/WP-API/WP-API/issues/2558#issuecomment-228608580","issue_url":"https://api.github.com/repos/WP-API/WP-API/issues/2558","id":228608580,"user":{"login":"27pchrisl","id":6286310,"avatar_url":"https://avatars.githubusercontent.com/u/6286310?v=3","gravatar_id":"","url":"https://api.github.com/users/27pchrisl","html_url":"https://github.com/27pchrisl","followers_url":"https://api.github.com/users/27pchrisl/followers","following_url":"https://api.github.com/users/27pchrisl/following{/other_user}","gists_url":"https://api.github.com/users/27pchrisl/gists{/gist_id}","starred_url":"https://api.github.com/users/27pchrisl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/27pchrisl/subscriptions","organizations_url":"https://api.github.com/users/27pchrisl/orgs","repos_url":"https://api.github.com/users/27pchrisl/repos","events_url":"https://api.github.com/users/27pchrisl/events{/privacy}","received_events_url":"https://api.github.com/users/27pchrisl/received_events","type":"User","site_admin":false},"created_at":"2016-06-26T16:07:34Z","updated_at":"2016-06-26T16:07:34Z","body":"Apparently it's the number of calls to __(), which only takes 33us per call (if I'm reading this right) but it reached up to 90,000 calls from the ~2500 times get_item_schema was called."}}
{"actor":{"display_login":"27pchrisl"}}