The Lambda build script (`app/otterwiki/build.sh`) strips all `.pyc` files and `__pycache__` directories to reduce package size. However, Lambda's package filesystem is read-only — Python cannot cache compiled bytecode at runtime. Every cold start recompiles every `.py` file it imports. Retaining pre-compiled `.pyc` files (or better, running `python -m compileall` during the build) skips the compilation step on cold start.
+
+
Estimated savings: 200-400ms. The bulk of import time is executing module-level code and loading C extensions, not bytecode compilation, so the improvement is modest. But the change is a one-liner with zero risk.
+
+
**Task:**
+
1. Remove the `find "$PACKAGE_DIR" -name "*.pyc" -delete` line from `build.sh`
+
2. Remove the `find "$PACKAGE_DIR" -type d -name "__pycache__" -exec rm -rf {} +` line
+
3. Add `python -m compileall -q "$PACKAGE_DIR"` after stripping to pre-compile all `.py` files
+
4. Measure package size delta
+
5. Re-run cold start benchmark to measure actual improvement
+
+
**Acceptance criteria:**
+
- [ ] `.pyc` files retained in Lambda package
+
- [ ] Cold start improvement measured and documented
An EventBridge rule invoking the otterwiki Lambda every 5 minutes keeps one execution environment warm, eliminating cold starts for the common case (single user browsing). Cost is effectively $0/month (8,760 invocations/month at 500ms × 512MB = 2,190 GB-seconds, well within the 400K GB-s free tier).
+
+
Limitations: only keeps 1 instance warm. Concurrent requests beyond 1 still cold-start. Does not solve the problem at scale — just masks it for low-traffic scenarios.
+
+
This is a band-aid, not a solution. The CDN read path ([[Tasks/E-2_CDN_Read_Path_ClientSide]]) is the proper fix. This task exists as a fallback if the CDN work is delayed.
+
+
**Task:**
+
1. Add EventBridge rule in `infra/__main__.py`: invoke otterwiki Lambda every 5 minutes
+
2. Add Lambda permission for EventBridge to invoke