Skip to content

Conversation

@vilsonrodrigues
Copy link
Contributor

Summary

Optimizes environment file check operations by replacing slower pathlib operations with faster os.path equivalents, resulting in massive performance improvements.

Performance Improvements

First-time load:

  • msgspec-ext: 1.818ms (1.5x faster than pydantic-settings)
  • pydantic-settings: 2.814ms

Cached loads (repeated loads in long-running apps):

  • msgspec-ext: 0.016ms (112x faster than pydantic-settings)
  • pydantic-settings: 1.818ms

Changes

Code Optimizations

  • ✅ Replace Path().absolute() with os.path.abspath() (2x faster)
  • ✅ Replace Path.exists() with os.path.exists() (3.5x faster)
  • ✅ Add fast return on cache hit to avoid unnecessary filesystem checks
  • ✅ Remove pathlib import (no longer needed)

README Improvements

  • ✅ Show first-time load numbers first (what users will see when testing)
  • ✅ Add separate section for cached performance with clear context
  • ✅ Merge redundant sections into clear "Why Choose msgspec-ext?"
  • ✅ Add practical use cases for each performance scenario
  • ✅ Explain caching benefits in accessible language

Testing

  • ✅ All 22 tests passing
  • ✅ Ruff linting passed
  • ✅ Benchmarks confirm performance improvements

Related

This PR focuses specifically on optimizing the env file check operations. A separate investigation into MessagePack vs JSON (branch perf/investigate-msgpack-vs-json) concluded that MessagePack doesn't provide real-world benefits for this use case.

vilsonrodrigues and others added 10 commits November 27, 2025 02:18
- Complete project structure overview
- Common commands and workflows
- Release process (always use ./scripts/release.sh)
- Architecture details and optimizations
- Linting, testing, and CI/CD guides
- Troubleshooting tips

This file provides context for Claude Code to work more effectively
with the project without repeating instructions.
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
* docs: Add CLAUDE.md with project guidelines

- Complete project structure overview
- Common commands and workflows
- Release process (always use ./scripts/release.sh)
- Architecture details and optimizations
- Linting, testing, and CI/CD guides
- Troubleshooting tips

This file provides context for Claude Code to work more effectively
with the project without repeating instructions.

* Add CHANGELOG.md for release tracking

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* RELEASE: v0.2.0

This release updates:
- version.py: 0.1.0 → 0.2.0
- CHANGELOG.md: Added release section for v0.2.0

After merging this PR:
- publish.yml workflow will trigger automatically
- Package will be built and published to PyPI
- GitHub release will be created with tag v0.2.0

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
…heckout (msgflux#19)

* docs: Add CLAUDE.md with project guidelines

- Complete project structure overview
- Common commands and workflows
- Release process (always use ./scripts/release.sh)
- Architecture details and optimizations
- Linting, testing, and CI/CD guides
- Troubleshooting tips

This file provides context for Claude Code to work more effectively
with the project without repeating instructions.

* Add CHANGELOG.md for release tracking

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: optimize env parser latency with advanced caching

- Add field name to env name mapping cache for faster lookups
- Add absolute path cache to avoid repeated pathlib operations
- Add type introspection cache for complex types (Union/Optional)
- Optimize _preprocess_env_value with fast paths for primitive types
- Optimize _get_env_name with fast path for no transformations
- Optimize _decode_from_dict with atomic encoder/decoder cache
- Add comprehensive benchmark suite with cold vs warm analysis
- Move profile_settings.py to benchmark/ directory
- All tests passing (22/22) and lint/format checks clean

Performance improvements:
- Main benchmark: 0.023ms per load (excellent consistency)
- Cold start: 1.489ms (1.3x faster than pydantic)
- Warm cached: 0.011ms (117.5x faster than pydantic)
- 129.6x speedup from cold to warm caching

* docs: update README with new performance metrics and optimizations

- Update benchmark results: 0.023ms per load (down from 2.271ms)
- Add cold vs warm performance comparison: 117.5x faster when cached
- Document advanced caching strategies implemented
- Update comparison table with new performance metrics
- Reflect 129.6x internal speedup from cold to warm caching

* fix: improve mergebot update command with better error handling and fork support

- Add branch existence validation before attempting checkout
- Add proper handling for PRs from forks with clear messaging
- Add detailed error messages for branch deletion, permission issues
- Add branch comparison logic to check if update is actually needed
- Add comprehensive debug logging for troubleshooting
- Handle edge cases where branch was deleted after merge
- Provide helpful instructions for manual updates when automation fails

* fix: improve mergebot /update command with better fork handling and checkout

This commit fixes several issues with the `/update` command in the mergebot workflow:

**Problems fixed:**
1. Checkout was trying to fetch branch from base repo instead of head repo
2. Branch comparison used incorrect reference format for same-repo PRs
3. Fork validation happened too late, causing unnecessary operations

**Changes:**
- Add early exit for fork PRs in "Get PR info" step with clear error message
- Specify repository parameter in checkout action to fetch from correct repo
- Simplify branch comparison to use simple branch reference for same-repo PRs
- Update validation conditions to skip unnecessary steps for fork PRs
- Remove redundant "Handle fork PR" step (now handled earlier)
- Add better logging for debugging

**Benefits:**
- Fork PRs now get immediate, clear feedback that update is not supported
- Same-repo PRs can now be updated correctly without checkout errors
- Better performance by skipping unnecessary operations for forks
- Cleaner code flow and easier maintenance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Fix template literal interpolation issue by extracting pr.base.ref to
a local variable before using it in the comment body. This prevents
YAML parsing errors with the GitHub Actions workflow.

The issue occurs when GitHub Actions tries to parse the workflow file
and encounters ${pr.base.ref} inside a JavaScript template literal,
which can be confused with GitHub Actions variable interpolation syntax.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Replace all problematic template literals with backticks inside YAML with
array-based string construction using .join('\n'). This prevents YAML parser
errors when GitHub Actions tries to validate the workflow file.

Changes:
- Fork PR message: Use array of strings instead of multiline template literal
- Success message: Extract to variable to avoid inline template complexity
- Failure message: Use array of strings for code block formatting

This approach avoids:
- Escaped backticks in YAML (\`\`\`)
- Complex template literals inside YAML string literals
- YAML scanner errors with 'could not find expected :'

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Performance optimizations:
- Replace Path().absolute() with os.path.abspath() (2x faster)
- Replace Path.exists() with os.path.exists() (3.5x faster)
- Add fast return on cache hit to avoid unnecessary checks
- Remove pathlib import (no longer needed)

Results:
- First load: 1.818ms (1.5x faster than pydantic-settings)
- Cached loads: 0.016ms (112x faster than pydantic-settings)
- All 22 tests passing ✅

README improvements:
- Show first-time load numbers first (what users will see when testing)
- Add separate section for cached performance with clear context
- Merge redundant sections into clear "Why Choose msgspec-ext?"
- Add practical use cases for each performance scenario
- Explain caching benefits in accessible language

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vilsonrodrigues vilsonrodrigues force-pushed the perf/optimize-env-file-check-v2 branch from fca70a4 to 68b0785 Compare December 2, 2025 22:11
@vilsonrodrigues
Copy link
Contributor Author

Closing this PR due to merge conflicts. Recreating with a clean branch in a new PR.

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