Skip to content

[API Review] Memory performance improvements #1971

Description

Currently we instantiate new objects every time for the following properties, this can have a large memory impact for large OpenAPI descriptions. For eg: For the Graph OpenAPI this will create 142k schemas, for a total of 1.1 million objects that might be unused. So we have an opportunity for some memory perf. improvements by lazily instantiating these.

 public virtual IDictionary<string, OpenApiSchema> PatternProperties { get; set; } = new Dictionary<string, OpenApiSchema>();
        public virtual IList<JsonNode> Enum { get; set; } = new List<JsonNode>();
        public virtual IList<OpenApiSchema> AllOf { get; set; } = new List<OpenApiSchema>();
        public virtual IList<OpenApiSchema> OneOf { get; set; } = new List<OpenApiSchema>();
        public virtual IList<OpenApiSchema> AnyOf { get; set; } = new List<OpenApiSchema>();
        public virtual ISet<string> Required { get; set; } = new HashSet<string>();
        public virtual IDictionary<string, OpenApiSchema> Properties { get; set; } = new Dictionary<string, OpenApiSchema>();
        public virtual IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

A couple of different ideas were identified:

  1. Lazy Instantiation: Explore using the init pattern and lazy get instantiation to reduce unnecessary object allocations in the OpenAPISchema
  2. Structs vs. Classes: Evaluate the possibility of redefining OpenAPISchema and other types as structs instead of classes to improve performance.
  3. IDictionary properties should have a default value and no setter.

Activity

  1. added
    priority:p1High priority but not blocking. Causes major but not critical loss of functionality SLA <=7days
    on Nov 26, 2024
  2. added
    priority:p0Blocking issue/ loss of critical functions. An ICM may be filed to communicate urgency. SLA<=48hrs
    and removed
    priority:p1High priority but not blocking. Causes major but not critical loss of functionality SLA <=7days
    on Dec 11, 2024
  3. added
    priority:p1High priority but not blocking. Causes major but not critical loss of functionality SLA <=7days
    and removed
    priority:p0Blocking issue/ loss of critical functions. An ICM may be filed to communicate urgency. SLA<=48hrs
    on Feb 6, 2025
  4. RachitMalik12 commented on Feb 26, 2025

    @RachitMalik12
    ContributorAuthor

    Sample of documents needed:

    1. Document that uses minimal features.
    2. Document that is more complex. (eg: point in time snapshot (via submodule) graph beta openapi spec)
      Use these as tests to see if the changes actually improve performance.
  5. RachitMalik12 commented on Feb 26, 2025

    @RachitMalik12
    ContributorAuthor

    We need to make a decision on whether we should use v1 as a baseline and then port the same testing to v2.

  6. baywet commented on Mar 28, 2025

    @baywet
    Member

    (assigned to myself to build the benchmarking and comparison infrastructure for this, Maggie should continue working on the performance improvements)

  7. RachitMalik12 commented on Apr 1, 2025

    @RachitMalik12
    ContributorAuthor

    Something that was removed from the docs, putting it here for reference, related to your comment Vincent Biret (@baywet)

    Potential Performance improvements

            public virtual IDictionary<string, OpenApiSchema> PatternProperties { get; set; } = new Dictionary<string, OpenApiSchema>();
            public virtual IList<JsonNode> Enum { get; set; } = new List<JsonNode>();
            public virtual IList<OpenApiSchema> AllOf { get; set; } = new List<OpenApiSchema>();
            public virtual IList<OpenApiSchema> OneOf { get; set; } = new List<OpenApiSchema>();
            public virtual IList<OpenApiSchema> AnyOf { get; set; } = new List<OpenApiSchema>();
            public virtual ISet<string> Required { get; set; } = new HashSet<string>();
            public virtual IDictionary<string, OpenApiSchema> Properties { get; set; } = new Dictionary<string, OpenApiSchema>();
            public virtual IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

WIPpriority:p1High priority but not blocking. Causes major but not critical loss of functionality SLA <=7days

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions