Skip to content

perf(validator): optimize schema caching and fix k6 teardown#198

Merged
qhanson55 merged 5 commits intomainfrom
perf/schema-cache
Mar 9, 2026
Merged

perf(validator): optimize schema caching and fix k6 teardown#198
qhanson55 merged 5 commits intomainfrom
perf/schema-cache

Conversation

@jujaga
Copy link
Copy Markdown
Member

@jujaga jujaga commented Mar 6, 2026

Description

This PR introduces a more robust and performant schema validation strategy by leveraging Ajv’s internal caching mechanisms and deterministic hashing. It also includes critical bug fixes for load testing scripts and general code quality improvements.

Key Changes

Schema & Validation Optimization

  • Deterministic Schema Hashing: Implemented stable stringification to ensure that identical schema objects produce consistent hashes.
  • Schema Identification: Added a utility to ensure all schemas have a unique $id, enabling efficient lookups within the Ajv registry.
  • Validation Refactor: Rewrote validateSchema to use a centralized Ajv instance. This reduces memory overhead by preventing the redundant creation of validator objects and ensuring repeated schemas are funneled to pre-compiled definitions.

Bug Fixes & Maintenance

  • k6 Load Testing: Fixed a bug in the putRecords teardown logic where test records were not being fully removed from the environment.
  • Code Quality: Performed a SonarQube cleanup sweep to address minor technical debt and maintainability issues.

Technical Details

The new validation flow utilizes an in-flight compilation map to deduplicate simultaneous requests for the same schema, preventing race conditions and redundant CPU usage during async compilation.

Related Issues/Tickets

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature that changes existing behavior)
  • Documentation update

Checklist

  • I have read the CONTRIBUTING guidelines
  • I have tested my changes locally
  • The code builds and passes all tests
  • I have updated documentation as needed

Instance Deployment

  • I require a cloud deployment for testing

Note

To request for a cloud deployment for testing purposes, add the deploy label to this PR.
Deployments will be removed when the PR is closed, merged, or the deploy label is removed.

Additional Notes

jujaga added 4 commits March 6, 2026 11:24
This utility will allow us to use ajv's built in schema caching support

Signed-off-by: Jeremy Ho <jujaga@gmail.com>
Signed-off-by: Jeremy Ho <jujaga@gmail.com>
Signed-off-by: Jeremy Ho <jujaga@gmail.com>
@jujaga jujaga requested a review from a team as a code owner March 6, 2026 22:33
@jujaga jujaga added bug Something isn't working enhancement New feature or request labels Mar 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 6, 2026

Coverage Report

Totals Coverage
Statements: 93.77% ( 1158 / 1235 )
Methods: 96% ( 168 / 175 )
Lines: 98.14% ( 632 / 644 )
Branches: 86.06% ( 358 / 416 )

This change slightly improves memory performance by generating fewer AJV
objects and using smarter logic to funnel repeated schema to the same
pre-compiled definition.

Signed-off-by: Jeremy Ho <jujaga@gmail.com>
@jujaga jujaga force-pushed the perf/schema-cache branch from d2f0c32 to 88170f5 Compare March 9, 2026 17:59
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 9, 2026

@qhanson55 qhanson55 merged commit 5bfc2fb into main Mar 9, 2026
24 checks passed
@qhanson55 qhanson55 deleted the perf/schema-cache branch March 9, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants