Skip to content

[Analyzer] Lift arrays of literals to static fields #78398

Closed as not planned
Closed as not planned

Description

@stephentoub

We should consider adding an info-level analyzer that flags cases where arrays of literals are being allocated and recommend they instead be lifted to be stored in static readonly fields. We'll need to experiment a bit to drive down false positive rates, e.g.

  • Don't warn if the array is returned out of the method.
  • Don't warn if the array is mutated by the method.
  • Don't warn if the array is being stored / passed immediately as a ReadOnlySpan<T>.

Related:
#33793

Activity

  1. added
    code-analyzerMarks an issue that suggests a Roslyn analyzer
    code-fixerMarks an issue that suggests a Roslyn code fixer
    on Nov 15, 2022
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Nov 15, 2022
  3. added this to the 8.0.0 milestone on Nov 16, 2022
  4. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 16, 2022
  5. added
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Nov 21, 2022
  6. modified the milestones: 8.0.0, Future on Jul 24, 2023
  7. buyaa-n commented on Mar 12, 2024

    @buyaa-n
    Contributor
  8. steveberdy commented on Aug 31, 2024

    @steveberdy
    Contributor

    This definitely looks the same to me

  9. buyaa-n commented on Sep 3, 2024

    @buyaa-n
    Contributor

    Yeah, doesn't see any difference, closing as duplicate

  10. locked and limited conversation to collaborators on Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Runtimecode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixer

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions