Skip to content

Conversation

@subomi
Copy link
Owner

@subomi subomi commented Jan 24, 2026

Summary

This PR introduces several core improvements to the requestmigrations library focused on performance, API clarity, and robustness.

1. Eager Graph Building (LR-2)

  • Before: Type graphs were built lazily at request time, causing lock contention and unpredictable latency
  • After: Graphs are now built eagerly at registration time with a lazy fallback for unregistered container types
  • Uses sync.Map for thread-safe cache access with minimal lock contention
  • No Finalize() step required—just register and use

2. API Surface Reduction (LR-3)

  • Made TypeGraphBuilder unexported (typeGraphBuilder) - internal implementation detail
  • Added cleaner request-scoped API: rm.For(req) / rm.Bind(req) returns a Migrator
  • Simplified usage pattern: rm.For(req).Marshal(&data) / rm.For(req).Unmarshal(body, &data)

3. Native Type Migration Validation (ME-3)

  • Added ErrNativeTypeMigration error for invalid registration attempts
  • Blocks registration of built-in primitives: string, int, bool, float64, etc.
  • Blocks unnamed composite types: []string, map[string]int, interface{}, error
  • Allows user-defined named types: type MyString string, type User struct{}, type Tags []string

4. Concurrency Improvements

  • Changed from sync.Mutex to sync.RWMutex for better read concurrency
  • Added sync.Map for graph cache (lock-free reads)

5. Test Coverage Expansion (LR-5)

  • Added comprehensive tests for complex types (nested structs, cycles, interfaces)
  • Added Test_MigrationTypeValidation with 18 test cases covering type validation
  • Added tests for eager graph building behavior
  • Added tests for concurrent access patterns

6. CI Improvements

  • Added -race flag to CI workflow for race condition detection

Files Changed

File Changes
requestmigrations.go +342/-304 - Core refactor with eager building, new API, validation
requestmigrations_test.go +1134/-? - Expanded test coverage
common.go +55 - Shared utilities
.github/workflows/go.yml +3 - Race detector
util.go -18 - Removed (consolidated)

Test Plan

  • All existing tests pass
  • New tests for type validation (18 cases)
  • Tests for eager graph building
  • Tests for concurrent access
  • Race detector enabled in CI

@subomi subomi merged commit c78b2e0 into main Jan 24, 2026
6 checks passed
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.

2 participants