Skip to content

Commit 82ce67b

Browse files
docs: update README with Google Colab benchmark results (7x faster)
1 parent 22a20e1 commit 82ce67b

File tree

2 files changed

+217
-223
lines changed

2 files changed

+217
-223
lines changed

README.md

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121

2222
## Features
2323

24-
-**High performance** - Built on msgspec for speed
24+
-**7x faster than pydantic-settings** - High performance built on msgspec
25+
-**Drop-in API compatibility** - Familiar interface, easy migration from pydantic-settings
2526
-**Type-safe** - Full type hints and validation
2627
-**.env support** - Fast built-in .env parser (no dependencies)
2728
-**Nested settings** - Support for complex configuration structures
2829
-**Zero dependencies** - Only msgspec required
29-
-**Familiar API** - Easy to learn if you've used settings libraries before
30+
-**169x faster cached loads** - Smart caching for repeated access
3031

3132
## Installation
3233

@@ -98,74 +99,81 @@ settings = AppSettings()
9899

99100
## Advanced Usage
100101

101-
### Custom .env file path
102+
### Nested Configuration
102103

103104
```python
104105
from msgspec_ext import BaseSettings, SettingsConfigDict
105106

106-
class AppSettings(BaseSettings):
107-
model_config = SettingsConfigDict(
108-
env_file=".env.production",
109-
env_file_encoding="utf-8"
110-
)
111-
112-
app_name: str
113-
```
114-
115-
### Prefix for environment variables
116-
117-
```python
118-
from msgspec_ext import BaseSettings, SettingsConfigDict
107+
class DatabaseSettings(BaseSettings):
108+
host: str = "localhost"
109+
port: int = 5432
110+
name: str = "myapp"
111+
user: str = "postgres"
112+
password: str = ""
119113

120114
class AppSettings(BaseSettings):
121115
model_config = SettingsConfigDict(
122-
env_prefix="MYAPP_"
116+
env_file=".env",
117+
env_nested_delimiter="__"
123118
)
119+
120+
name: str = "My App"
121+
debug: bool = False
122+
database: DatabaseSettings
124123

125-
name: str # Will look for MYAPP_NAME
124+
# Loads nested config from DATABASE__HOST, DATABASE__PORT, etc.
125+
settings = AppSettings()
126+
print(settings.database.host) # from DATABASE__HOST env var
126127
```
127128

128-
### Case sensitivity
129+
### Custom Validation
129130

130131
```python
131132
from msgspec_ext import BaseSettings, SettingsConfigDict
133+
from typing import Literal
132134

133135
class AppSettings(BaseSettings):
134-
model_config = SettingsConfigDict(
135-
case_sensitive=True
136-
)
136+
model_config = SettingsConfigDict(env_file=".env")
137+
138+
# Custom validation with enums
139+
environment: Literal["development", "staging", "production"] = "development"
140+
141+
# JSON parsing from environment variables
142+
features: list[str] = ["auth", "api"]
143+
limits: dict[str, int] = {"requests": 100, "timeout": 30}
137144

138-
AppName: str # Exact match required
145+
settings = AppSettings()
146+
print(settings.features) # Automatically parsed from JSON string
139147
```
140148

141149
## Why Choose msgspec-ext?
142150

143151
msgspec-ext provides a **faster, lighter alternative** to pydantic-settings while maintaining a familiar API and full type safety.
144152

145-
### Performance Comparison
153+
### Performance Comparison (Google Colab Results)
146154

147-
**Cold start** (first load, includes .env parsing):
155+
**Cold start** (first load, includes .env parsing) - *Benchmarked on Google Colab*:
148156

149157
| Library | Time per load | Speed |
150158
|---------|---------------|-------|
151-
| **msgspec-ext** | **0.39ms** | **5.0x faster**|
152-
| pydantic-settings | 1.95ms | Baseline |
159+
| **msgspec-ext** | **0.353ms** | **7.0x faster**|
160+
| pydantic-settings | 2.47ms | Baseline |
153161

154-
**Warm (cached)** (repeated loads in long-running applications):
162+
**Warm (cached)** (repeated loads in long-running applications) - *Benchmarked on Google Colab*:
155163

156164
| Library | Time per load | Speed |
157165
|---------|---------------|-------|
158-
| **msgspec-ext** | **0.012ms** | **267x faster**|
159-
| pydantic-settings | 3.2ms | Baseline |
166+
| **msgspec-ext** | **0.011ms** | **169x faster**|
167+
| pydantic-settings | 1.86ms | Baseline |
160168

161-
> *Benchmark includes .env file parsing, environment variable loading, type validation, and nested configuration (app settings, database, redis, feature flags). Run `benchmark/benchmark_cold_warm.py` to reproduce.*
169+
> *Benchmark executed on Google Colab includes .env file parsing, environment variable loading, type validation, and nested configuration. Run `benchmark/benchmark_cold_warm.py` on Google Colab to reproduce these results.*
162170
163171
### Key Advantages
164172

165173
| Feature | msgspec-ext | pydantic-settings |
166174
|---------|------------|-------------------|
167-
| **Cold start** | **5.0x faster**| Baseline |
168-
| **Warm (cached)** | **267x faster**| Baseline |
175+
| **Cold start** | **7.0x faster**| Baseline |
176+
| **Warm (cached)** | **169x faster**| Baseline |
169177
| **Package size** | **0.49 MB** | 1.95 MB |
170178
| **Dependencies** | **1 (msgspec only)** | 5+ |
171179
| .env support | ✅ Built-in | ✅ Via python-dotenv |
@@ -180,25 +188,19 @@ msgspec-ext provides a **faster, lighter alternative** to pydantic-settings whil
180188
msgspec-ext achieves its performance through:
181189
- **Bulk validation**: Validates all fields at once in C (via msgspec), not one-by-one in Python
182190
- **Custom .env parser**: Built-in fast parser with zero external dependencies (no python-dotenv overhead)
183-
- **Smart caching**: Caches .env files, field mappings, and type information - loads after the first are 267x faster
191+
- **Smart caching**: Caches .env files, field mappings, and type information - loads after the first are 169x faster
184192
- **Optimized file operations**: Uses fast os.path operations instead of slower pathlib alternatives
185193
- **Zero overhead**: Fast paths for common types (str, bool, int, float) with minimal Python code
186194

187195
This means your application **starts faster** and uses **less memory**, especially important for:
188-
- 🚀 **CLI tools** - 5.0x faster startup every time you run the command
196+
- 🚀 **CLI tools** - 7.0x faster startup every time you run the command
189197
-**Serverless functions** - Lower cold start latency means better response times
190-
- 🔄 **Long-running apps** - After the first load, reloading settings is 267x faster (12 microseconds!)
198+
- 🔄 **Long-running apps** - After the first load, reloading settings is 169x faster (11 microseconds!)
191199

192200
## Contributing
193201

194202
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
195203

196204
## License
197205

198-
MIT License - see [LICENSE](LICENSE) file for details.
199-
200-
## Links
201-
202-
- [GitHub Repository](https://github.com/msgflux/msgspec-ext)
203-
- [PyPI Package](https://pypi.org/project/msgspec-ext/)
204-
- [msgspec Documentation](https://jcristharif.com/msgspec/)
206+
MIT License - see [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)