{"action":"opened","issue":{"url":"https://api.github.com/repos/althea-mesh/althea_rs/issues/207","repository_url":"https://api.github.com/repos/althea-mesh/althea_rs","labels_url":"https://api.github.com/repos/althea-mesh/althea_rs/issues/207/labels{/name}","comments_url":"https://api.github.com/repos/althea-mesh/althea_rs/issues/207/comments","events_url":"https://api.github.com/repos/althea-mesh/althea_rs/issues/207/events","html_url":"https://github.com/althea-mesh/althea_rs/issues/207","id":350766079,"node_id":"MDU6SXNzdWUzNTA3NjYwNzk=","number":207,"title":"Refactor Regex instances into lazy_static! scope","user":{"login":"mpapierski","id":327556,"node_id":"MDQ6VXNlcjMyNzU1Ng==","avatar_url":"https://avatars3.githubusercontent.com/u/327556?v=4","gravatar_id":"","url":"https://api.github.com/users/mpapierski","html_url":"https://github.com/mpapierski","followers_url":"https://api.github.com/users/mpapierski/followers","following_url":"https://api.github.com/users/mpapierski/following{/other_user}","gists_url":"https://api.github.com/users/mpapierski/gists{/gist_id}","starred_url":"https://api.github.com/users/mpapierski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpapierski/subscriptions","organizations_url":"https://api.github.com/users/mpapierski/orgs","repos_url":"https://api.github.com/users/mpapierski/repos","events_url":"https://api.github.com/users/mpapierski/events{/privacy}","received_events_url":"https://api.github.com/users/mpapierski/received_events","type":"User","site_admin":false},"labels":[{"id":1025019782,"node_id":"MDU6TGFiZWwxMDI1MDE5Nzgy","url":"https://api.github.com/repos/althea-mesh/althea_rs/labels/refactor","name":"refactor","color":"bbc924","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-15T10:48:47Z","updated_at":"2018-08-15T10:48:47Z","closed_at":null,"author_association":"COLLABORATOR","body":"There are some places where we create Regex instance with every call to a function. Regex crate has this benefit that compilation stage might take longer for the benefit of guaranteed linear search. It would be perhaps a small benefit for the runtime performance to keep instances of regular expressions. On the other hand we might notice a small performance gain on constrained CPUs we target at (i.e. constant linear search vs expensive compile + search).\r\n\r\n# Example\r\n\r\nBad:\r\n\r\n```rust\r\nfn foo(input: &str) {\r\n    re = Regex::new(\"xyz\").unwrap();\r\n    for caps in re.captures_iter(input) { ... }\r\n}\r\n```\r\n\r\nGood:\r\n\r\n```rust\r\nfn foo(input: &str) {\r\n    lazy_static! {\r\n        static ref re : Regex = Regex::new(\"xyz\").expect(\"Unable to compile regular expression\");\r\n    }\r\n    for caps in re.captures_iter(input) { ... }\r\n}\r\n```\r\n\r\nOn the other hand it might seem as premature optimization, though. I'd judge this that this is really a nobrainer to refactor it for a positive benefit.\r\n\r\nSource: https://github.com/rust-lang/regex/blob/master/PERFORMANCE.md#thou-shalt-not-compile-regular-expressions-in-a-loop"}}
{"actor":{"display_login":"mpapierski"}}