Title: Consider replacing `foreach` on IList/List with `for` loop · Issue #138 · microsoft/SqlScriptDOM · GitHub
Open Graph Title: Consider replacing `foreach` on IList/List with `for` loop · Issue #138 · microsoft/SqlScriptDOM
X Title: Consider replacing `foreach` on IList/List with `for` loop · Issue #138 · microsoft/SqlScriptDOM
Description: When parsing thousands of scripts foreach approach generates at least N * 2 unnecessary enumerators, e.g. in TSQL160Parser here and here. Also somewhere in the deep of generated code it produces lots (~N*10) of enumerators on IList Open Graph Description: When parsing thousands of scripts foreach approach generates at least N * 2 unnecessary enumerators, e.g. in TSQL160Parser here and here. Also somewhere in the deep of generated code it produces lo...
X Description: When parsing thousands of scripts foreach approach generates at least N * 2 unnecessary enumerators, e.g. in TSQL160Parser here and here. Also somewhere in the deep of generated code it produces lo...
Opengraph URL: https://github.com/microsoft/SqlScriptDOM/issues/138
X: @github
Domain: patch-diff.githubusercontent.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Consider replacing `foreach` on IList/List with `for` loop","articleBody":"When parsing thousands of scripts `foreach` approach generates at least N * 2 unnecessary enumerators, e.g. in TSQL160Parser [here](https://github.com/microsoft/SqlScriptDOM/blob/42f5cad3e7faeee7010a889ea09bea65512db84d/SqlScriptDom/Parser/TSql/TSql150Parser.cs#L89) and [here](https://github.com/microsoft/SqlScriptDOM/blob/42f5cad3e7faeee7010a889ea09bea65512db84d/SqlScriptDom/Parser/TSql/TSql150Parser.cs#L115).\n\nAlso somewhere in the deep of generated code it produces lots (~N*10) of enumerators on `IList\u003cIdentifier\u003e` but I was unable to locate this place. It'd be great if this was fixed too.\n\nAlso please take a look at this `IEnumerable` [implicit cast](https://github.com/microsoft/SqlScriptDOM/blob/42f5cad3e7faeee7010a889ea09bea65512db84d/tools/AstGen/ClassDescription.cs#L249) wherease the source is `List` and some code addressing this `IEnumerable` with `foreach` could be actually rewritten into more optimal `for`. And there is another suspicious `foreach` a couple of [lines below](https://github.com/microsoft/SqlScriptDOM/blob/42f5cad3e7faeee7010a889ea09bea65512db84d/tools/AstGen/ClassDescription.cs#L260) which may affect iterating through children objects. Perhaps it will work faster and with less garbage objects for GC if implemented as `for` loop and index-based access to `IList` elements.","author":{"url":"https://github.com/IVNSTN","@type":"Person","name":"IVNSTN"},"datePublished":"2025-06-21T13:33:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/138/SqlScriptDOM/issues/138"}
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:00242cff-208d-7936-4bae-e27f32b86ce0 current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id 957C:6868A:5720AC:781CD1:698EF7BA html-safe-nonce 8f9692fae959f7f872784cc18e446cb535436f572a8e0c39c1bca06951baefe5 visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTdDOjY4NjhBOjU3MjBBQzo3ODFDRDE6Njk4RUY3QkEiLCJ2aXNpdG9yX2lkIjoiODQ2MzY4NDkxMDU3MzM1Mjg5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 visitor-hmac c8b2af5a605cd18f675546671fcc4cb8171d609c4e68d80b45c165e05040a411 hovercard-subject-tag issue:3165095159 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/microsoft/SqlScriptDOM/138/issue_layout twitter:image https://opengraph.githubassets.com/06b661f9b00707f83002f26a50f0a87208f5144bc3ffd793893aa148707aeee1/microsoft/SqlScriptDOM/issues/138 twitter:card summary_large_image og:image https://opengraph.githubassets.com/06b661f9b00707f83002f26a50f0a87208f5144bc3ffd793893aa148707aeee1/microsoft/SqlScriptDOM/issues/138 og:image:alt When parsing thousands of scripts foreach approach generates at least N * 2 unnecessary enumerators, e.g. in TSQL160Parser here and here. Also somewhere in the deep of generated code it produces lo... og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username IVNSTN hostname github.com expected-hostname github.com None 7f7bf82d8907f81525d95af82e60354b419d083df9534c8631d06bb9c0bf07ac turbo-cache-control no-preview go-import github.com/microsoft/SqlScriptDOM git https://github.com/microsoft/SqlScriptDOM.git octolytics-dimension-user_id 6154722 octolytics-dimension-user_login microsoft octolytics-dimension-repository_id 543316377 octolytics-dimension-repository_nwo microsoft/SqlScriptDOM octolytics-dimension-repository_public true octolytics-dimension-repository_is_fork false octolytics-dimension-repository_network_root_id 543316377 octolytics-dimension-repository_network_root_nwo microsoft/SqlScriptDOM 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 bc36007ff5167349dcfee9a75c7fa7184ab272c4 ui-target full theme-color #1e2327 color-scheme light dark
URLs of crawlers that visited me.