Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(query): optimize field processing with caching #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fyvri
Copy link

@fyvri fyvri commented Jan 19, 2025

This PR introduces a caching mechanism to optimize the processing of struct fields in the query package. The main goal is to reduce redundant reflection operations when encoding structs into URL query parameters, especially for nested or deeply embedded structs.

Key Changes:

  1. Added Caching:

    • Introduced a structCache map to store field information for each struct type, avoiding repeated reflection operations.
    • Field information is computed once and reused for subsequent encoding of the same struct type.
  2. Improved Performance:

    • Reduced the overhead of reflection by caching field metadata, leading to faster encoding of structs.
    • This is particularly beneficial for applications that frequently encode large or nested structs.
  3. Backward Compatibility:

    • The external API remains unchanged, ensuring no breaking changes for existing users.

Impact:

  • Faster Encoding: The caching mechanism significantly improves performance by reducing redundant reflection calls.
  • Low Memory Overhead: The cache introduces minimal memory usage, with a clear performance benefit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant