Skip to content

[Repo Assist] perf: cache property name/metadata lookups in getPropertyValues#373

Merged
sergey-tihon merged 4 commits intomasterfrom
repo-assist/perf-cache-property-metadata-20260411-230d90e019a5c10a
Apr 11, 2026
Merged

[Repo Assist] perf: cache property name/metadata lookups in getPropertyValues#373
sergey-tihon merged 4 commits intomasterfrom
repo-assist/perf-cache-property-metadata-20260411-230d90e019a5c10a

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

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

Background

getPropertyValues is called at request time for every API call that uses form-encoded or multipart bodies (toFormUrlEncodedContent / toMultipartFormDataContent). On each invocation it previously performed:

  1. GetProperties(Public | Instance) — a reflection lookup over the type
  2. Per property: GetCustomAttributes(typeof<JsonPropertyNameAttribute>, false) — another reflection lookup to resolve the JSON-serialised name

Both calls are re-done for every request even when the same model type is used repeatedly.

Fix

Introduce propNameCache: ConcurrentDictionary<Type, (string * PropertyInfo)[]> that memoises the (serialized-name, PropertyInfo) array for each type on first use. Subsequent calls to getPropertyValues for the same type skip both GetProperties and per-property GetCustomAttributes entirely.

This is consistent with the existing propCache used by formatObject for the same reason.

Changes

File Change
src/SwaggerProvider.Runtime/RuntimeHelpers.fs Add propNameCache + getPropertyNamesAndInfos helper; refactor getPropertyValues to use the cache

Test Status

✅ Build: succeeded (0 errors, pre-existing warnings only)
✅ Unit tests: 316 passed, 0 failed, 2 skipped (same as baseline)
✅ Format check: fantomas applied and re-verified clean

Integration/provider tests require a running Swashbuckle test server and were not run; the change does not touch schema parsing, type compilation, or HTTP dispatch logic.

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

To install this agentic workflow, run

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

Previously getPropertyValues called GetProperties() and GetCustomAttributes()
via reflection on every invocation. These are O(n) per call even for the
same type. The existing propCache for formatObject demonstrated the same
pattern.

Add propNameCache: ConcurrentDictionary<Type, (string * PropertyInfo)[]>
that memoises the (serialized-name, PropertyInfo) array for each type on
first use. Subsequent calls to getPropertyValues for the same type skip
both GetProperties and per-property GetCustomAttributes entirely.

This benefits APIs that use form-encoded or multipart bodies
(toFormUrlEncodedContent / toMultipartFormDataContent) for clients that
make repeated calls with the same model types.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sergey-tihon sergey-tihon marked this pull request as ready for review April 11, 2026 13:09
Copilot AI review requested due to automatic review settings April 11, 2026 13:09
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

Improves request-time performance in SwaggerProvider.Runtime by caching reflection lookups used to extract object properties for form-encoded and multipart request bodies, avoiding repeated property enumeration and JsonPropertyNameAttribute inspection for the same model types.

Changes:

  • Added a ConcurrentDictionary<Type, (string * PropertyInfo)[]> cache for serialized property name + PropertyInfo pairs.
  • Refactored getPropertyValues to use the cached (name, PropertyInfo) pairs instead of re-running reflection each call.

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

…unwrapping, cache path)

Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/7ba4f18b-f8e6-4339-9d3e-6f9b3106efc0

Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Copilot AI requested a review from sergey-tihon April 11, 2026 14:00
@sergey-tihon sergey-tihon reopened this Apr 11, 2026
@sergey-tihon sergey-tihon merged commit ed72b94 into master Apr 11, 2026
9 of 11 checks passed
@sergey-tihon sergey-tihon deleted the repo-assist/perf-cache-property-metadata-20260411-230d90e019a5c10a branch April 11, 2026 16:46
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.

3 participants