{"action":"created","issue":{"url":"https://api.github.com/repos/jwiegley/use-package/issues/308","labels_url":"https://api.github.com/repos/jwiegley/use-package/issues/308/labels{/name}","comments_url":"https://api.github.com/repos/jwiegley/use-package/issues/308/comments","events_url":"https://api.github.com/repos/jwiegley/use-package/issues/308/events","html_url":"https://github.com/jwiegley/use-package/pull/308","id":127140553,"number":308,"title":"Do not package-initialize on each :pin","user":{"login":"kovrik","id":2239626,"avatar_url":"https://avatars.githubusercontent.com/u/2239626?v=3","gravatar_id":"","url":"https://api.github.com/users/kovrik","html_url":"https://github.com/kovrik","followers_url":"https://api.github.com/users/kovrik/followers","following_url":"https://api.github.com/users/kovrik/following{/other_user}","gists_url":"https://api.github.com/users/kovrik/gists{/gist_id}","starred_url":"https://api.github.com/users/kovrik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kovrik/subscriptions","organizations_url":"https://api.github.com/users/kovrik/orgs","repos_url":"https://api.github.com/users/kovrik/repos","events_url":"https://api.github.com/users/kovrik/events{/privacy}","received_events_url":"https://api.github.com/users/kovrik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-18T02:00:14Z","updated_at":"2016-01-19T21:52:30Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jwiegley/use-package/pulls/308","html_url":"https://github.com/jwiegley/use-package/pull/308","diff_url":"https://github.com/jwiegley/use-package/pull/308.diff","patch_url":"https://github.com/jwiegley/use-package/pull/308.patch"},"body":"In #302 @adouzzy mentioned that using lots of `:pin` makes startup time very long.\r\nEven main page says:\r\n>NOTE: if you pin a lot of packages, it will be slightly slower to start Emacs compared to manually adding all packages to the package-pinned-packages variable. However, should you do it this way, you need to keep track of when (package-initialize) is called, so letting use-package handle it for you is arguably worth the cost.\r\n\r\nI noticed that in `use-package-pin-package` function we always call `(package-initialize t)`.\r\n(I don't know though if it's done for purpose or not. If yes, then ignore this pull request)\r\n\r\nFor some reasons, `package-initialize` does not check if `package` has already been initialized.\r\nThat function loads all descriptors and reads all archive contents.\r\nObviously, it's not a very fast function.\r\n\r\n**Benchmarks:**\r\n``` lisp\r\n;; use-package-pin-package\r\n(benchmark 100 '(use-package-pin-package \"test1234\" \"gnu\"))\r\n\r\n;; add-to-list\r\n(benchmark 100 '(add-to-list 'package-pinned-packages '(test1234 . \"gnu\")))\r\n\r\n;; => Elapsed time: 13.770000s (3.888000s in 200 GCs)\r\n;; => Elapsed time: 0.000000s\r\n```\r\n\r\nWhoah!\r\n\r\nInside `package.el` itself they do:\r\n``` lisp\r\n(unless package--initialized\r\n  (package-initialize t))\r\n```\r\nMakes sense.\r\n\r\nThat's what I've done in this pull-request:\r\nCheck if `package--initialized` var is bound (just for sure) and then check it's value.\r\nIf it is `nil` then call `package-initialize t` once.\r\nIn all other cases assume that `package` has been initialized.\r\n\r\n**Benchmarks (after this patch):**\r\n``` lisp\r\n;; use-package-pin-package\r\n(benchmark 100 '(use-package-pin-package \"test1234\" \"gnu\"))\r\n\r\n;; add-to-list\r\n(benchmark 100 '(add-to-list 'package-pinned-packages '(test1234 . \"gnu\")))\r\n\r\n;; => Elapsed time: 0.000000s\r\n;; => Elapsed time: 0.000000s\r\n```\r\n\r\n@jwiegley @npostavs @thomasf \r\nWould you kindly review this pull-request and do some tests please?"},"comment":{"url":"https://api.github.com/repos/jwiegley/use-package/issues/comments/172999772","html_url":"https://github.com/jwiegley/use-package/pull/308#issuecomment-172999772","issue_url":"https://api.github.com/repos/jwiegley/use-package/issues/308","id":172999772,"user":{"login":"kovrik","id":2239626,"avatar_url":"https://avatars.githubusercontent.com/u/2239626?v=3","gravatar_id":"","url":"https://api.github.com/users/kovrik","html_url":"https://github.com/kovrik","followers_url":"https://api.github.com/users/kovrik/followers","following_url":"https://api.github.com/users/kovrik/following{/other_user}","gists_url":"https://api.github.com/users/kovrik/gists{/gist_id}","starred_url":"https://api.github.com/users/kovrik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kovrik/subscriptions","organizations_url":"https://api.github.com/users/kovrik/orgs","repos_url":"https://api.github.com/users/kovrik/repos","events_url":"https://api.github.com/users/kovrik/events{/privacy}","received_events_url":"https://api.github.com/users/kovrik/received_events","type":"User","site_admin":false},"created_at":"2016-01-19T21:52:30Z","updated_at":"2016-01-19T21:52:30Z","body":"@npostavs \r\nThank you!\r\nChanged the condition."}}