Title: Performance problem: -cmatch prevents automatic caching of on-demand-compiled regexes · Issue #8941 · PowerShell/PowerShell · GitHub
Open Graph Title: Performance problem: -cmatch prevents automatic caching of on-demand-compiled regexes · Issue #8941 · PowerShell/PowerShell
X Title: Performance problem: -cmatch prevents automatic caching of on-demand-compiled regexes · Issue #8941 · PowerShell/PowerShell
Description: Note: This isn't a bug per se, but a performance issue. Note that -creplace and switch -regex -casesensitive appear NOT to be affected. Steps to reproduce $strArray = , 'foo' * 1e5 # an array with N elements containing 'foo' # Contrast t...
Open Graph Description: Note: This isn't a bug per se, but a performance issue. Note that -creplace and switch -regex -casesensitive appear NOT to be affected. Steps to reproduce $strArray = , 'foo' * 1e5 # an array with ...
X Description: Note: This isn't a bug per se, but a performance issue. Note that -creplace and switch -regex -casesensitive appear NOT to be affected. Steps to reproduce $strArray = , 'foo' * 1e5 # an...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/8941
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Performance problem: -cmatch prevents automatic caching of on-demand-compiled regexes","articleBody":"Note: This isn't a _bug_ per se, but a _performance issue_.\r\n\r\nNote that `-creplace` and `switch -regex -casesensitive` appear NOT to be affected.\r\n\r\n# Steps to reproduce\r\n\r\n```powershell\r\n$strArray = , 'foo' * 1e5 # an array with N elements containing 'foo'\r\n# Contrast the performance of -match vs. -cmatch\r\n$scriptBlocks = \r\n { foreach ($str in $strArray) { $null = $str -match 'f?(o)' } },\r\n { foreach ($str in $strArray) { $null = $str -cmatch 'f?(o)' } }\r\n\r\n$scriptBlocks | % { (Measure-Command $_).TotalSeconds }\r\n```\r\n\r\n# Expected behavior\r\n\r\nRoughly the same execution time in both cases - `-cmatch` should actually be slightly _faster_.\r\n\r\n# Actual behavior\r\n\r\nSample result from my macOS 10.14.3 machine:\r\n\r\n```none\r\n0.6651756\r\n1.3135713\r\n```\r\n\r\nThat is, `-cmatch` unexpectedly took about _twice as long_.\r\n\r\nThat this may be related to unexpectedly _bypassing_ .NET's automatic caching of on-demand-compiled regexes is evidenced by the fact that if you _force_ caching as follows, the problem goes away:\r\n\r\n```powershell\r\n# Forces caching of the regex; running the above code again then performs as expected.\r\n$null = switch -casesensitive -regex ($null) { 'f?(o)' { } }\r\n```\r\n\r\n# Environment data\r\n\r\n```none\r\nPowerShell Core v6.2.0-preview.4 on macOS 10.14.2\r\nPowerShell Core v6.2.0-preview.4 on Ubuntu 18.04.1 LTS\r\nPowerShell Core v6.2.0-preview.4 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.471)\r\nWindows PowerShell v5.1.17134.407 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.471)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2019-02-21T17:04:45Z","url":"https://github.com/PowerShell/PowerShell/issues/8941"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ffa0957e-b111-1c0d-e648-8291a5a0273c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8710:2F1BC5:A7A74:E5346:6AFD4A1C |
| html-safe-nonce | dbc33c8aae406770c78287378367e273f3d5830e76e1cf64fa40dd79b94d5feb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzEwOjJGMUJDNTpBN0E3NDpFNTM0Njo2QUZENEExQyIsInZpc2l0b3JfaWQiOiIxNzgxNzQzNTA2Mzg1ODgxNjI4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 81084875ea93e7b29535c561476facadd1da3b0c217fd2cc06a3c43bd5cd83ee |
| hovercard-subject-tag | issue:413029785 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/8941/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a651b061f89e20c46513f4e7e98e4ec2d4ea40061a968a8a9bcec1f9deef864f/PowerShell/PowerShell/issues/8941 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a651b061f89e20c46513f4e7e98e4ec2d4ea40061a968a8a9bcec1f9deef864f/PowerShell/PowerShell/issues/8941 |
| og:image:alt | Note: This isn't a bug per se, but a performance issue. Note that -creplace and switch -regex -casesensitive appear NOT to be affected. Steps to reproduce $strArray = , 'foo' * 1e5 # an array with ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width