Title: High cpu usage when parsing scripts that include [ordered] · Issue #17308 · PowerShell/PowerShell · GitHub
Open Graph Title: High cpu usage when parsing scripts that include [ordered] · Issue #17308 · PowerShell/PowerShell
X Title: High cpu usage when parsing scripts that include [ordered] · Issue #17308 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/17308
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"High cpu usage when parsing scripts that include [ordered]","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\r\n- [X] Search the existing issues.\r\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\r\n\r\n### Steps to reproduce\r\n\r\nWe are parsing multiple powershell scripts in parallel using Parser.ParseInput but are having issues with perf when the scrips being parsed includes multiple [ordered] attributes/types.\r\n\r\nThe parser starts to use 100% cpu, and it takes a long time for the parsing to complete.\r\n\r\n[Repro here](https://github.com/Sjark/PowershellParsingIssue)\r\n\r\nThe console app above has 2 identical powershell scripts included, the only difference is that on of them has a bunch of [ordered] before the hashtable assignments.\r\n\r\nThe one without [ordered] completes almost instantly, while the one with [ordered] takes some time and uses a lot of cpu.\r\n\r\n### Expected behavior\r\n\r\n```console\r\nParsing to complete in about the same time with both scripts.\r\n```\r\n\r\n\r\n### Actual behavior\r\n\r\n```console\r\nParsing takes a lot longer and uses a lot more resources when the script includes [ordered].\r\n```\r\n\r\n\r\n### Error details\r\n\r\nThe error seems to be related to `LookForTypeInAssemblies` method within the TypeResolver.cs:68\r\n\r\nEvery time it finds a [ordered] in the script it goes through all loaded assemblies to try and find the matching type, but since [ordered] is not actually a type (just a helper for creating `System.Collections.Specialized.OrderedDictionary`) the method returns null, and will search again the next time it finds an [ordered] attribute.\r\n\r\nI think there should either be a cache for types that did not match any assemblies, so that it doesn't have to look through the same assemblies for the same type multiple times, or there should be a special case for [ordered] so that it does not even try to search through the assemblies for it.\r\n\r\n\r\n### Environment data\r\n\r\n```powershell\r\nWe are using nuget package: System.Management.Automation version 7.2.3\r\n```\r\n\r\n\r\n### Visuals\r\n\r\n_No response_","author":{"url":"https://github.com/Sjark","@type":"Person","name":"Sjark"},"datePublished":"2022-05-11T07:37:18Z","url":"https://github.com/PowerShell/PowerShell/issues/17308"}
| 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:7dc79dfe-de34-c5d6-0787-6f16279e22ca |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA22:1EB498:AC75A3:F92D88:6AFDA418 |
| html-safe-nonce | 743fd8ee3265e017688194c29dfd8d53cccf20dee612dc91074f56a68cced975 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTIyOjFFQjQ5ODpBQzc1QTM6RjkyRDg4OjZBRkRBNDE4IiwidmlzaXRvcl9pZCI6IjEwMTIzOTQ1OTU5OTgwODIwNzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 22a72449b0a05ee040f41df0917033165e8c802e0dccb109ddba88f7e7b330f3 |
| hovercard-subject-tag | issue:1232146852 |
| 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/17308/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6a953209b90346b65a0c2aa97c30c51024c645623ed36aba120f9f58d307acd2/PowerShell/PowerShell/issues/17308 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6a953209b90346b65a0c2aa97c30c51024c645623ed36aba120f9f58d307acd2/PowerShell/PowerShell/issues/17308 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Sjark |
| hostname | github.com |
| expected-hostname | github.com |
| None | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| 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 | 0ddf53eb35c87f1f8df13dbf75c3bdadbfc6e969 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width