Skip to content

[repo-assist] perf: avoid allOf double-isEmpty + Array.IndexOf in CallAsync; add V3 schema tests (+5 tests, 438→443)#445

Merged
sergey-tihon merged 3 commits into
masterfrom
repo-assist/perf-and-tests-20260520-e4d8a006c36abb99
May 21, 2026
Merged

[repo-assist] perf: avoid allOf double-isEmpty + Array.IndexOf in CallAsync; add V3 schema tests (+5 tests, 438→443)#445
sergey-tihon merged 3 commits into
masterfrom
repo-assist/perf-and-tests-20260520-e4d8a006c36abb99

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Three improvements across Tasks 8 (Performance) and 10 (Take Repository Forward).

Performance: cache Seq.isEmpty allOf in DefinitionCompiler (Task 8)

In compileBySchema, the allOf sequence was evaluated with Seq.isEmpty twice — once for schemaObjProperties and once for schemaObjRequired. Each call iterates up to the first element. The result is now cached in allOfEmpty and reused:

// Before (two Seq.isEmpty calls)
match Seq.isEmpty allOf with | false -> ... | true -> ...  // for properties
match Seq.isEmpty allOf with | false -> ... | true -> ...  // for required

// After (one cached call)
let allOfEmpty = Seq.isEmpty allOf
if allOfEmpty then ... else ...  // properties
if allOfEmpty then ... else ...  // required

Performance: Array.IndexOf in CallAsync (Task 8)

ProvidedApiClientBase.CallAsync used Array.tryFindIndex((=) codeStr), which allocates a partial-application closure on every non-success HTTP response. Replaced with System.Array.IndexOf, which avoids the closure:

// Before
match errorCodes |> Array.tryFindIndex((=) codeStr) with
| Some idx -> ...
| None -> ...

// After
let errorIdx = System.Array.IndexOf(errorCodes, codeStr)
if errorIdx >= 0 then ... else ...

New V3 schema compilation tests (Task 10)

Added 5 tests to Schema.V3SchemaCompilationTests.fs covering previously untested compiler behaviour:

Test What it covers
required property compiles to non-option type required: [id]int32
optional property compiles to option type omitted from requiredstring option
string enum schema compiles to a named enum type type: string, enum: [...] → type named Status
string enum type is an enum compiled type has IsEnum = true
object schema description is surfaced as XmlDoc description field → XmlDoc attribute

Test Status

Total: 443, Errors: 0, Failed: 0, Skipped: 1, Time: 1.036s

438 → 443 (+5 new tests). Build: 0 errors, 209 warnings (pre-existing).

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@dcdf09723d42ef9b6c75335e4612fd145d4ccdaa

… schema tests (+5 tests, 438→443)

- DefinitionCompiler: cache Seq.isEmpty allOf result to avoid iterating the
  sequence twice when building schemaObjProperties and schemaObjRequired
- ProvidedApiClientBase.CallAsync: replace Array.tryFindIndex((=) codeStr) with
  Array.IndexOf to avoid allocating a partial-application closure per error response
- Schema.V3SchemaCompilationTests: add 5 new tests covering required vs optional
  property types, string enum compilation, and schema description as XmlDoc

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sergey-tihon sergey-tihon marked this pull request as ready for review May 20, 2026 20:52
Copilot AI review requested due to automatic review settings May 20, 2026 20:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets small performance improvements in runtime error handling and design-time schema compilation, and expands OpenAPI v3 schema compilation test coverage to validate required/optional property typing, string-enum generation, and XmlDoc emission.

Changes:

  • Cache Seq.isEmpty allOf in DefinitionCompiler.compileBySchema to avoid double enumeration.
  • Replace Array.tryFindIndex ((=) codeStr) with System.Array.IndexOf in ProvidedApiClientBase.CallAsync to avoid per-call closure allocation on error responses.
  • Add 5 OpenAPI v3 schema compilation tests covering required vs optional property typing, string enum generation, and schema description → XmlDoc.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/SwaggerProvider.Tests/Schema.V3SchemaCompilationTests.fs Adds 5 new unit tests for v3 schema compilation behavior (required/optional properties, string enums, XmlDoc).
src/SwaggerProvider.Runtime/ProvidedApiClientBase.fs Optimizes error-code lookup in CallAsync using System.Array.IndexOf.
src/SwaggerProvider.DesignTime/DefinitionCompiler.fs Avoids repeated Seq.isEmpty allOf checks by caching the result during object type compilation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/SwaggerProvider.Tests/Schema.V3SchemaCompilationTests.fs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sergey-tihon sergey-tihon merged commit dffe960 into master May 21, 2026
2 checks passed
@sergey-tihon sergey-tihon deleted the repo-assist/perf-and-tests-20260520-e4d8a006c36abb99 branch May 21, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants