Efficient and safe scripts
Bound the work and state of every call, and measure instead of assuming speed.
Work per call
- Limit the players, entities, items, strings and server calls handled in one call.
- Avoid repeated serialization, large clones, allocations every tick and world-wide scans.
- Split large jobs into bounded steps with a way to cancel them.
- Keep logs useful and rate-limited.
What costs what
A call that reads a value is cheap. A call that can fire events costs more: breaking or placing a block, spawning an entity or teleporting runs the block or entity logic, and every script that listens to the events it fires. A blocking handler is waited for; an observer is not.
Permission checks, food level changes and experience changes run at the cost of a read when no script listens to the events they fire (player permission check, food level change, level change and experience change). Listening to those events makes every such call more expensive for every script, so listen only when you need them.
Concurrency
Your script runs one call at a time. Send and Sync bounds let the SDK store your handlers; they do not mean your code runs in parallel with itself. Use the scheduler for later work and check the state again when it runs. Do not start a task per entity or per tick.
Memory
Give caches and pending operations size limits. Clear player state on disconnect and when a menu closes. Repeat load and unload cycles before you claim memory is stable. The limits the server enforces are in Limits, failures and restarts.
Integrity
Check script and player input. Respect cancellation. Make one-off rewards, transfers and charges safe against repeated requests, and keep saves recoverable.
Measure the feature
Compare the same workload before and after a change:
- how long the game waits for your handlers and tasks (the console's
plugin time); - the console lines about slow calls and events your script is behind with;
- the result in the game.
A successful build or a single reading is not proof of speed or correctness.