|
|
|
|
|
by Cthulhu_
1733 days ago
|
|
I think it's easy to assume that in this case Go's regex library would keep an internal cache of expressions, using the expression string as a map key. But on the other, I can see why they haven't implemented it, because it obscures memory usage from direct control of the author. It would probably be a good idea to add performance hints like 'prefer to put static regular expressions in a package variable' in a linter or go vet. |
|
Moving static (at least as much it concerns the loop) expressions out of a loop is one of the most fundamental optimizations a programmer should do when writing code.