Commit f3a97bf
authored
feat: add function to calculate dynamic default Actor memory (#570)
This PR introduces the logic to calculate a dynamic default Actor memory
limit based on a provided expression string.
**TL;DR:**
- Uses a sandboxed MathJS instance to securely evaluate expressions.
- Supports `{{variable}}` placeholders with strict validation: `input.*`
paths are allowed, while `runOptions.*` keys are strictly
whitelisted(only 7 variables allowed).
- Injects the Actor input and run options into the evaluation scope.
- Adds a custom `get(obj, path, default)` helper to safely access nested
properties without crashing on missing paths (e.g., `get(input,
'startUrls.length', 0)`).
- Rounds the evaluated result to the closest valid power-of-2 memory
tier. Result is clamped to min/max range. (128MB-32GB)
Note: when using this function in our API, we'll use it in
`worker_thread`. I didn't add worker_thread to this package, because I
suppose it can be used from client-side as well.
More context: [Dynamic default Actor run memory notion
spec](https://www.notion.so/apify/Dynamic-default-Actor-memory-WIP-293f39950a2280b9aa34fa9cd07f52a4?source=copy_link)1 parent 27fa703 commit f3a97bf
File tree
10 files changed
+699
-0
lines changed- packages/actor-memory-expression
- src
- test
10 files changed
+699
-0
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments