{"action":"created","issue":{"url":"https://api.github.com/repos/rejeep/f.el/issues/93","repository_url":"https://api.github.com/repos/rejeep/f.el","labels_url":"https://api.github.com/repos/rejeep/f.el/issues/93/labels{/name}","comments_url":"https://api.github.com/repos/rejeep/f.el/issues/93/comments","events_url":"https://api.github.com/repos/rejeep/f.el/issues/93/events","html_url":"https://github.com/rejeep/f.el/issues/93","id":333024975,"node_id":"MDU6SXNzdWUzMzMwMjQ5NzU=","number":93,"title":"Optimization for directory-files","user":{"login":"alphapapa","id":601365,"node_id":"MDQ6VXNlcjYwMTM2NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/601365?v=4","gravatar_id":"","url":"https://api.github.com/users/alphapapa","html_url":"https://github.com/alphapapa","followers_url":"https://api.github.com/users/alphapapa/followers","following_url":"https://api.github.com/users/alphapapa/following{/other_user}","gists_url":"https://api.github.com/users/alphapapa/gists{/gist_id}","starred_url":"https://api.github.com/users/alphapapa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphapapa/subscriptions","organizations_url":"https://api.github.com/users/alphapapa/orgs","repos_url":"https://api.github.com/users/alphapapa/repos","events_url":"https://api.github.com/users/alphapapa/events{/privacy}","received_events_url":"https://api.github.com/users/alphapapa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-17T00:29:17Z","updated_at":"2018-09-07T03:19:35Z","closed_at":null,"author_association":"NONE","body":"Hi there,\r\n\r\nIn this interesting [discussion](https://github.com/Alexander-Miller/pfuture/issues/2#issuecomment-397843363) with Alexander Miller, he mentioned that `directory-files` is faster when called in a temp buffer.  This quick test seems to show that it is indeed:\r\n\r\n```org\r\n#+BEGIN_SRC elisp\r\n  (defun f--collect-entries--tb (path recursive)\r\n    (with-temp-buffer\r\n      (let (result\r\n            (entries\r\n             (-reject\r\n              (lambda (file)\r\n                (or\r\n                 (equal (f-filename file) \".\")\r\n                 (equal (f-filename file) \"..\")))\r\n              (directory-files path t))))\r\n        (cond (recursive\r\n               (-map\r\n                (lambda (entry)\r\n                  (if (f-file? entry)\r\n                      (setq result (cons entry result))\r\n                    (when (f-directory? entry)\r\n                      (setq result (cons entry result))\r\n                      (setq result (append result (f--collect-entries entry recursive))))))\r\n                entries))\r\n              (t (setq result entries)))\r\n        result)))\r\n\r\n\r\n  (list (cons \"without temp buffer\"\r\n              (progn\r\n                (garbage-collect)\r\n                (benchmark-run-compiled 100\r\n                  (f--collect-entries \"~/.emacs.d\" nil))))\r\n        (cons \"with temp buffer\"\r\n              (progn\r\n                (garbage-collect)\r\n                (benchmark-run-compiled 100\r\n                  (f--collect-entries--tb \"~/.emacs.d\" nil)))))\r\n#+END_SRC\r\n\r\n#+RESULTS:\r\n| without temp buffer | 0.31999160200000004 | 0 | 0.0 |\r\n| with temp buffer    |         0.191897104 | 0 | 0.0 |\r\n```\r\nI thought I should let you know in so that it could be added to `f--collect-entries`.  Seems like a nice, free optimization.  :)\r\n\r\nThanks for your work on f.el!"},"comment":{"url":"https://api.github.com/repos/rejeep/f.el/issues/comments/419309956","html_url":"https://github.com/rejeep/f.el/issues/93#issuecomment-419309956","issue_url":"https://api.github.com/repos/rejeep/f.el/issues/93","id":419309956,"node_id":"MDEyOklzc3VlQ29tbWVudDQxOTMwOTk1Ng==","user":{"login":"alphapapa","id":601365,"node_id":"MDQ6VXNlcjYwMTM2NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/601365?v=4","gravatar_id":"","url":"https://api.github.com/users/alphapapa","html_url":"https://github.com/alphapapa","followers_url":"https://api.github.com/users/alphapapa/followers","following_url":"https://api.github.com/users/alphapapa/following{/other_user}","gists_url":"https://api.github.com/users/alphapapa/gists{/gist_id}","starred_url":"https://api.github.com/users/alphapapa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphapapa/subscriptions","organizations_url":"https://api.github.com/users/alphapapa/orgs","repos_url":"https://api.github.com/users/alphapapa/repos","events_url":"https://api.github.com/users/alphapapa/events{/privacy}","received_events_url":"https://api.github.com/users/alphapapa/received_events","type":"User","site_admin":false},"created_at":"2018-09-07T03:19:35Z","updated_at":"2018-09-07T03:19:35Z","author_association":"NONE","body":"I rediscovered this in my notes, came here to repost it, and found that I already had.  :)  Here's another benchmark using `bench-multi`:\r\n\r\n```el\r\n(defun f--collect-entries--tb (path recursive)\r\n  (with-temp-buffer\r\n    (let (result\r\n          (entries\r\n           (-reject\r\n            (lambda (file)\r\n              (or\r\n               (equal (f-filename file) \".\")\r\n               (equal (f-filename file) \"..\")))\r\n            (directory-files path t))))\r\n      (cond (recursive\r\n             (-map\r\n              (lambda (entry)\r\n                (if (f-file? entry)\r\n                    (setq result (cons entry result))\r\n                  (when (f-directory? entry)\r\n                    (setq result (cons entry result))\r\n                    (setq result (append result (f--collect-entries entry recursive))))))\r\n              entries))\r\n            (t (setq result entries)))\r\n      result)))\r\n```\r\n```org\r\n#+BEGIN_SRC el\r\n  (bench-multi :times 100\r\n    :ensure-equal t\r\n    :forms ((\"without temp buffer\" (f--collect-entries \"~/.emacs.d\" nil))\r\n            (\"with temp buffer\" (f--collect-entries--tb \"~/.emacs.d\" nil))))\r\n#+END_SRC\r\n```\r\n Form                | x faster than next |       Total runtime | # of GCs | Total GC runtime \r\n--------------------- | -------------------- | --------------------- | ---------- | ------------------\r\n with temp buffer    | 1.66               |         0.087498083 |        0 |              0.0 \r\n without temp buffer | slowest            | 0.14550272800000003 |        0 |              0.0 "}}
{"actor":{"display_login":"alphapapa"}}