Skip to content

Commit ae8fdb2

Browse files
docs(build_recipes): add performance optimization page (#7197)
* Adding build page * Adding build page * Adding build page * Adding build page * Adding build page
1 parent f88e8a0 commit ae8fdb2

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Performance Optimization
3+
description: Optimize Lambda functions for better performance and reduced costs
4+
---
5+
6+
<!-- markdownlint-disable MD043 -->
7+
8+
Optimize your Lambda functions for better performance, reduced cold start times, and lower costs. These techniques help minimize package size, improve startup speed, and reduce memory usage.
9+
10+
## Reduce cold start times
11+
12+
1. **Minimize package size** by excluding unnecessary files
13+
2. **Use compiled dependencies** when possible
14+
3. **Leverage Lambda SnapStart** or **Provisioned concurrency** when possible
15+
16+
## Build optimization
17+
18+
=== "Exclude unnecessary files"
19+
20+
```bash
21+
--8<-- "examples/build_recipes/build_optimization/optimize-package.sh"
22+
```
23+
24+
=== "Layer optimization"
25+
26+
```bash
27+
--8<-- "examples/build_recipes/build_optimization/optimize-layer.sh"
28+
```
29+
30+
=== "Advanced optimization with debug symbol removal"
31+
32+
```bash
33+
--8<-- "examples/build_recipes/build_optimization/optimize-advanced.sh"
34+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# Remove unnecessary files
4+
find build/ -name "*.pyc" -delete
5+
find build/ -name "__pycache__" -type d -exec rm -rf {} +
6+
find build/ -name "*.dist-info" -type d -exec rm -rf {} +
7+
find build/ -name "tests" -type d -exec rm -rf {} +
8+
find build/ -name "test_*" -delete
9+
10+
# Remove debug symbols from compiled extensions
11+
find build/ -name "*.so" -exec strip --strip-debug {} \; 2>/dev/null || true
12+
find build/ -name "*.so.*" -exec strip --strip-debug {} \; 2>/dev/null || true
13+
14+
# Remove additional bloat from common packages
15+
rm -rf build/*/site-packages/*/tests/
16+
rm -rf build/*/site-packages/*/test/
17+
rm -rf build/*/site-packages/*/.git/
18+
rm -rf build/*/site-packages/*/docs/
19+
rm -rf build/*/site-packages/*/examples/
20+
rm -rf build/*/site-packages/*/*.md
21+
rm -rf build/*/site-packages/*/*.rst
22+
rm -rf build/*/site-packages/*/*.txt
23+
24+
# Calculate size reduction
25+
echo "📊 Package optimization completed"
26+
du -sh build/ 2>/dev/null || echo "✅ Advanced optimization applied"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# Create optimized layer structure
4+
mkdir -p layer/python/
5+
6+
# Install only production dependencies
7+
pip install aws-lambda-powertools[all] -t layer/python/ --no-deps
8+
pip install pydantic -t layer/python/ --no-deps
9+
10+
# Remove unnecessary files from layer
11+
find layer/ -name "*.pyc" -delete
12+
find layer/ -name "__pycache__" -type d -exec rm -rf {} +
13+
find layer/ -name "tests" -type d -exec rm -rf {} +
14+
15+
# Create layer zip
16+
cd layer && zip -r ../optimized-layer.zip . && cd ..
17+
18+
echo "✅ Optimized layer created: optimized-layer.zip"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Remove unnecessary files to reduce package size
4+
find build/ -name "*.pyc" -delete
5+
find build/ -name "__pycache__" -type d -exec rm -rf {} +
6+
find build/ -name "*.dist-info" -type d -exec rm -rf {} +
7+
find build/ -name "tests" -type d -exec rm -rf {} +
8+
find build/ -name "test_*" -delete
9+
10+
# Remove documentation and examples
11+
find build/ -name "docs" -type d -exec rm -rf {} +
12+
find build/ -name "examples" -type d -exec rm -rf {} +
13+
14+
echo "✅ Package optimized"

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ nav:
4141
- Build recipes:
4242
- build_recipes/index.md
4343
- Getting started: build_recipes/getting-started.md
44+
- Performance optimization: build_recipes/performance-optimization.md
4445
- CI/CD integration: build_recipes/cicd-integration.md
4546
- Troubleshooting: build_recipes/troubleshooting.md
4647
- Upgrade guide: upgrade.md
@@ -242,6 +243,7 @@ plugins:
242243
Build recipes:
243244
- build_recipes/index.md
244245
- build_recipes/getting-started.md
246+
- build_recipes/performance-optimization.md
245247
- build_recipes/cicd-integration.md
246248
- build_recipes/troubleshooting.md
247249

0 commit comments

Comments
 (0)