{"action":"created","issue":{"url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/530","labels_url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/530/labels{/name}","comments_url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/530/comments","events_url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/530/events","html_url":"https://github.com/squizlabs/PHP_CodeSniffer/issues/530","id":66218997,"number":530,"title":"Caching between runs for better performance","user":{"login":"JDGrimes","id":4005415,"avatar_url":"https://avatars.githubusercontent.com/u/4005415?v=3","gravatar_id":"","url":"https://api.github.com/users/JDGrimes","html_url":"https://github.com/JDGrimes","followers_url":"https://api.github.com/users/JDGrimes/followers","following_url":"https://api.github.com/users/JDGrimes/following{/other_user}","gists_url":"https://api.github.com/users/JDGrimes/gists{/gist_id}","starred_url":"https://api.github.com/users/JDGrimes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JDGrimes/subscriptions","organizations_url":"https://api.github.com/users/JDGrimes/orgs","repos_url":"https://api.github.com/users/JDGrimes/repos","events_url":"https://api.github.com/users/JDGrimes/events{/privacy}","received_events_url":"https://api.github.com/users/JDGrimes/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/labels/Enhancement","name":"Enhancement","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":20,"created_at":"2015-04-03T20:02:07Z","updated_at":"2015-05-05T12:13:49Z","closed_at":null,"body":"First let me thank you for this great tool. :+1: \r\n\r\nI've been using this on my PHP projects, and I've found that it can take a while to sniff the code, especially on larger projects with complex configurations. Performance will naturally be determined largely by how well the sniffs used are written. However, I think that performance could be increased by caching the hash signatures of the files being sniffed. Then only those files which have changes since the last sniff was conducted would need to be sniffed (there are some caveats which I'll get to in a moment). This wouldn't improve the performance of the initial sniffing (and might even degrade it slightly), but would drastically improve performance for latter sniffings.\r\n\r\nAs I noted above, there are some caveats:\r\n\r\n- **The cache needs to be invalidated when the configuration changes.** This would be when the XML config file is edited, for example, and possibly at other times as well. This could be facilitated by saving a hash signature of these configuration settings to the cache, and checking whether this matches the current configuration when the cache is being loaded.\r\n- **If a file has errors, the errors still need to get reported on subsequent sniffings even if the file hasn't changed.** This could be done by not caching files with errors, or by caching a list of the errors found and replaying them to the user without sniffing those files.\r\n\r\nThere are probably other things I haven't thought of, maybe regarding interactive mode, reports, or automatic fixing, all of which I am unfamiliar with. And there would probably need to be an easy way for the user to bypass the cache as needed.\r\n\r\nThere are probably also other things that could be cached between runs on a project as well.\r\n\r\nExactly how the cache is saved is up to you. I was thinking of a `.phpcs-cache` in the root of the project being sniffed that would contain the cache represented as a JSON object.\r\n\r\nIf this is something that you think could be done, I'd be happy to work up a PR if you'll give me a little guidance on how you'd like this implemented."},"comment":{"url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/comments/99063374","html_url":"https://github.com/squizlabs/PHP_CodeSniffer/issues/530#issuecomment-99063374","issue_url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/530","id":99063374,"user":{"login":"aik099","id":1277526,"avatar_url":"https://avatars.githubusercontent.com/u/1277526?v=3","gravatar_id":"","url":"https://api.github.com/users/aik099","html_url":"https://github.com/aik099","followers_url":"https://api.github.com/users/aik099/followers","following_url":"https://api.github.com/users/aik099/following{/other_user}","gists_url":"https://api.github.com/users/aik099/gists{/gist_id}","starred_url":"https://api.github.com/users/aik099/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aik099/subscriptions","organizations_url":"https://api.github.com/users/aik099/orgs","repos_url":"https://api.github.com/users/aik099/repos","events_url":"https://api.github.com/users/aik099/events{/privacy}","received_events_url":"https://api.github.com/users/aik099/received_events","type":"User","site_admin":false},"created_at":"2015-05-05T12:13:49Z","updated_at":"2015-05-05T12:13:49Z","body":"> I don't know what file you are talking about.\r\n\r\nThe file, that can be used as per-project PHP_CodeSniffer.conf file. It guess it's `phpcs.xml` then."}}