{"action":"created","issue":{"url":"https://api.github.com/repos/ripple/rippled/issues/939","labels_url":"https://api.github.com/repos/ripple/rippled/issues/939/labels{/name}","comments_url":"https://api.github.com/repos/ripple/rippled/issues/939/comments","events_url":"https://api.github.com/repos/ripple/rippled/issues/939/events","html_url":"https://github.com/ripple/rippled/pull/939","id":63093158,"number":939,"title":"[Performance] Remove unnecessary allocation / deallocation from Application::masterLock","user":{"login":"HowardHinnant","id":6708789,"avatar_url":"https://avatars.githubusercontent.com/u/6708789?v=3","gravatar_id":"","url":"https://api.github.com/users/HowardHinnant","html_url":"https://github.com/HowardHinnant","followers_url":"https://api.github.com/users/HowardHinnant/followers","following_url":"https://api.github.com/users/HowardHinnant/following{/other_user}","gists_url":"https://api.github.com/users/HowardHinnant/gists{/gist_id}","starred_url":"https://api.github.com/users/HowardHinnant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HowardHinnant/subscriptions","organizations_url":"https://api.github.com/users/HowardHinnant/orgs","repos_url":"https://api.github.com/users/HowardHinnant/repos","events_url":"https://api.github.com/users/HowardHinnant/events{/privacy}","received_events_url":"https://api.github.com/users/HowardHinnant/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ripple/rippled/labels/Josh","name":"Josh","color":"eeeeee"},{"url":"https://api.github.com/repos/ripple/rippled/labels/Scott.D","name":"Scott.D","color":"eeeeee"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-19T21:21:27Z","updated_at":"2015-03-19T21:47:05Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ripple/rippled/pulls/939","html_url":"https://github.com/ripple/rippled/pull/939","diff_url":"https://github.com/ripple/rippled/pull/939.diff","patch_url":"https://github.com/ripple/rippled/pull/939.patch"},"body":"Every time we call getApp().getMasterLock() we are doing a new for the lock, and a delete for the unlock.  This is ridiculously expensive.  And part of the reason that nobody noticed we are doing this is because the code is over encapsulated.\r\n\r\nThis PR gets rid of the extra (hidden) new/delete, and also de-complicates the code:  The `Application` is now only responsible for providing the mutex.  The client that needs to lock the mutex is responsible for providing the lock, and deciding how to lock the mutex.  This makes it much clearer that there is nothing (like memory allocation) behind the curtain, because there is no more curtain.\r\n\r\nTo this end a new utility `make_lock` is introduced which deduces the correct lock type, based on the type of mutex passed to it.  This is only a convenience, and the client does not have to use it.  It is anticipated that this pattern will be followed in other places as well, and so `make_lock` may be reused in more places.  However `Application::masterLock` is the only place where there is currently a known performance penalty that needs fixing.\r\n\r\nAlso in one place a potential deadlock is fixed.  There currently is no deadlock.  But the code is very hard to read and prove to one's self that it can't deadlock.  The rewritten version proposed here is trivial to read and know there is no deadlock.\r\n\r\nThis PR is subdivided into 5 simple steps for ease in reviewing (from top to bottom).  These can be folded if desired.\r\n\r\n@josh-ripple @seelabs  (or whoever has time to volunteer)"},"comment":{"url":"https://api.github.com/repos/ripple/rippled/issues/comments/83772066","html_url":"https://github.com/ripple/rippled/pull/939#issuecomment-83772066","issue_url":"https://api.github.com/repos/ripple/rippled/issues/939","id":83772066,"user":{"login":"scottschurr","id":7840379,"avatar_url":"https://avatars.githubusercontent.com/u/7840379?v=3","gravatar_id":"","url":"https://api.github.com/users/scottschurr","html_url":"https://github.com/scottschurr","followers_url":"https://api.github.com/users/scottschurr/followers","following_url":"https://api.github.com/users/scottschurr/following{/other_user}","gists_url":"https://api.github.com/users/scottschurr/gists{/gist_id}","starred_url":"https://api.github.com/users/scottschurr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottschurr/subscriptions","organizations_url":"https://api.github.com/users/scottschurr/orgs","repos_url":"https://api.github.com/users/scottschurr/repos","events_url":"https://api.github.com/users/scottschurr/events{/privacy}","received_events_url":"https://api.github.com/users/scottschurr/received_events","type":"User","site_admin":false},"created_at":"2015-03-19T21:47:05Z","updated_at":"2015-03-19T21:47:05Z","body":"Nicely organized code.  Very easy to read the changes.  Thanks for the tutorial."}}