# Reducing the default maximum script execution effort on the execution node to 9999 computation units

**URL:** <https://forum.flow.com/t/reducing-the-default-maximum-script-execution-effort-on-the-execution-node-to-9999-computation-units/6130>\
**Category:** Flow Protocol\
**Tags:** cadence, script\
**Created:** [June 2, 2024, 7:09am UTC](https://forum.flow.com/t/reducing-the-default-maximum-script-execution-effort-on-the-execution-node-to-9999-computation-units/6130 "2024-06-02T07:09:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishal](https://avatars.discourse-cdn.com/v4/letter/v/49beb7/32.png) [@vishal](https://forum.flow.com/u/vishal)\
**Post date:** [June 2, 2024, 7:09am UTC](https://forum.flow.com/t/reducing-the-default-maximum-script-execution-effort-on-the-execution-node-to-9999-computation-units/6130/1 "2024-06-02T07:09:20Z")

</div>

Scripts are a light-weight method to query chain data. Scripts, unlike transactions, can only read chain data and not modify it. Also unlike a transaction, script do not require any transaction fees. For more information about what are scripts and how to use them, please refer to this [link](https://developers.flow.com/build/basics/scripts).

Scripts serve well for several use cases such as validating a transaction before submitting it, chain auditing etc. (more examples [here](https://developers.flow.com/build/basics/scripts#when-to-use-a-script)). However, scripts are currently executed on the execution node and hence they compete with transactions for resources (CPU, memory etc.) on the execution node.

Currently, the default maximum execution effort for a script is 100K, which means a user can submit a script which can use up to 100K in computation units on an execution node. Compare this to the maximum execution effort for a transaction which is currently set to 9999.

> I propose that the default maximum script execution computation limit set on an execution node, be reduced to **9999** (same as the maximum for a transaction) from the current 100K limit.

The following are the main reasons for it:

1. **Fair play**

2. **Disburden the execution nodes**

## Impact of the change

1. 
### The change will impact only around 4% of the scripts

After the change, scripts which require more than 9999 in execution effort will start failing. Let’s look at what percentage of scripts will be impacted.

The following table describes the computation units used by scripts on an execution node on mainnet on June 1st, looking back 90 days and averaging over a one-day time interval.

| Percentile | Computation units |
| --- | --- |
| 96th Percentile | 9776 |
| 95th Percentile | 9604 |
| 50th Percentile (median) | 144 |
| Average (mean) | 3526 |

As can be seen, 96% of all the total scripts that were executed, used less than 10K computation units.

Hence, the proposed change will only affect around 4% of the submitted scripts.

Currently, the average number of scripts executed per second is ~30 per second (looking back 90 days). Hence this change only impacts ~2 scripts (per second).

For comparison, here are the computation units used by transactions,

| Percentile | Computation units |
| --- | --- |
| 99th Percentile | 4853 |
| 95th Percentile | 3860 |
| 50th Percentile (median) | 207 |
| Average (mean) | 870 |

Computation units used by transactions are well below the maximum permissible limit of 9999 and also lesser than scripts.

The data was reported for the [script\_computation\_used](https://github.com/onflow/flow-go/blob/9585ddfad60d561eab728e0893b4bfb9064e75f5/module/metrics/execution.go#L451) and the [transaction\_computation\_used](https://github.com/onflow/flow-go/blob/9585ddfad60d561eab728e0893b4bfb9064e75f5/module/metrics/execution.go#L403) metric by the two execution nodes run by the foundation. Refer to the [Appendix](https://forum.flow.com/t/reducing-the-default-maximum-script-execution-effort-on-the-execution-node-to-9999-computation-units/6130#appendix-6) for more data.

Scripts that use more than 9999 computation units can be refactored to use fewer computation units. [Here](https://developers.flow.com/build/basics/scripts#best-practices) are some best practices for revising such scripts.

1. 
### Script execution on the access node

Script execution on the access node is now ready! Access nodes can now sync execution state data and optionally execute scripts locally without forwarding the script request to an execution node. This is a major unlock as it enables unbounded non-rate limited script execution on a self-hosted access node. It also allows users to run scripts which require more than 10K computation units on their self-hosted access nodes.

## Note

1. The proposal is to change the default computation limit for scripts. However, an execution node operator can override this default and choose a different and possibly more stricter limit.

2. This proposal should not be mixed with the rate limits on the script execution API call. Those limits define the acceptable rate of requests per second by the access node operators.

## Rollout

The change can be rolled out in stages going from 100K (current limit) to 50K first. And then, after a few weeks, going down from 50K to 25K and eventually to 9,999. Such a gradual rollout will allow everyone to revise their scripts.

I would appreciate your feedback and am more than happy to answer any questions or gather more data.

Thank you,

Vishal

## Appendix

Following is a heat map showing the distribution of computation used by scripts over time confirming that only a small percentage of scripts use more than 10000 computation units.

 ![](https://us1.discourse-cdn.com/flex022/uploads/flow/original/2X/b/b5175a9101c6c55c0785a8a67538a448b170a765.png)

---

<div class="post-metadata">

**Author:** ![vishal](https://avatars.discourse-cdn.com/v4/letter/v/49beb7/32.png) [@vishal](https://forum.flow.com/u/vishal)\
**Post date:** [June 2, 2024, 7:11am UTC](https://forum.flow.com/t/reducing-the-default-maximum-script-execution-effort-on-the-execution-node-to-9999-computation-units/6130/2 "2024-06-02T07:11:13Z")

</div>

[Link](https://discord.com/channels/613813861610684416/1236110629295624253) to the discord discussion earlier on this topic

---

<div class="post-metadata">

**Author:** ![bluesign](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/bluesign/32/1359_2.png) [@bluesign](https://forum.flow.com/u/bluesign)\
**Post date:** [June 3, 2024, 7:34am UTC](https://forum.flow.com/t/reducing-the-default-maximum-script-execution-effort-on-the-execution-node-to-9999-computation-units/6130/3 "2024-06-03T07:34:14Z")

</div>

I think this is very much needed. Currently scripts can create very heavy load.
