[Repo Assist] perf+refactor: cache HttpMethod lookups; extract XmlDoc.combineDescAndEnum helper#415
Conversation
…dEnum helper Task 8 (Performance): createHttpRequest previously called HttpMethod(httpMethod.ToUpper()) on every API invocation. Since generated clients bake the method string in at compile time, the same uppercase verb is passed on every call. Replace with a pre-built readOnlyDict of the 8 standard HTTP verbs mapped to their static HttpMethod instances, avoiding the ToUpper() string allocation and HttpMethod constructor overhead on the hot path. Task 5 (Coding improvement): the four-case (description × enum-doc) match pattern to build XML documentation strings was duplicated verbatim in DefinitionCompiler.fs (property doc) and OperationCompiler.fs (parameter doc). Extract it to XmlDoc.combineDescAndEnum in Utils.fs and call it from both sites, reducing duplication and making future changes easier. Tests: 348/348 passing (unchanged from baseline). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copilot fix build |
…tpMethod("PATCH")
Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/073a911f-7007-4c53-ba59-2ebb8ebc434c
Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Fixed in cb59795. |
There was a problem hiding this comment.
Pull request overview
This PR bundles two small quality improvements: a runtime performance optimization for HTTP method handling in request creation, and a design-time refactor to centralize duplicated XML-doc composition logic.
Changes:
- Cache standard
HttpMethodinstances and resolve via a prebuilt dictionary inRuntimeHelpers.createHttpRequest. - Extract duplicated “description + enum doc” combination logic into
XmlDoc.combineDescAndEnum. - Update both
DefinitionCompilerandOperationCompilerto use the new helper.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/SwaggerProvider.Runtime/RuntimeHelpers.fs | Adds cached resolution of standard HTTP verbs to avoid per-call allocations. |
| src/SwaggerProvider.DesignTime/Utils.fs | Introduces XmlDoc.combineDescAndEnum helper to consolidate repeated doc-building logic. |
| src/SwaggerProvider.DesignTime/OperationCompiler.fs | Uses the new helper when building parameter XML-doc text. |
| src/SwaggerProvider.DesignTime/DefinitionCompiler.fs | Uses the new helper when building property XML-doc text. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot address inline commit |
… ToUpperInvariant in fallback Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/75e303c9-440c-479f-ad5f-0ad74e956843 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
|
@copilot fix the build |
Replace `dictionary[m.Method] <- m` (F# 6+ index setter shorthand) with `dictionary.Add(m.Method, m)` to avoid potential fantomas formatting edge cases in CI environments. Semantically equivalent. Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/fd02ef57-a258-421e-b5c0-a3f74b4ac535 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Fixed in fb5b5d6. Replaced Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Two independent improvements bundled in one small PR.
Task 8 — Performance: cache
HttpMethodinstances increateHttpRequestcreateHttpRequestis called on every generated client method invocation. It previously did:Because generated clients bake the HTTP verb string in at compile time (
opTy.ToString()returns uppercase at design time), the same uppercase string is passed on every call. TheToUpper()allocation andHttpMethodconstructor were pure overhead.Fix: a
readOnlyDictof the 8 standard HTTP verbs →HttpMethodstatic instances is built once at module initialisation.resolveHttpMethoddoes a single dictionary lookup and only falls back toHttpMethod(method.ToUpper())for non-standard verbs.Task 5 — Coding improvement: extract
XmlDoc.combineDescAndEnumThe four-case match expression to combine a schema description with optional enum-value documentation was duplicated verbatim in two places:
DefinitionCompiler.fs— building XML doc for generated object propertiesOperationCompiler.fs— building XML doc for operation parametersFix: extract to
XmlDoc.combineDescAndEnuminUtils.fsand call it from both sites. Reduces duplication and makes future changes (e.g. different separator, HTML escaping) a single-site edit.Test Status
dotnet builddotnet fantomas --checkSwaggerProvider.Tests)Closes no specific issue. Both are independent quality improvements.