Dev Feature 8 - Contract Wide CPU Optimizations #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: This merge is for demonstration purposes & will be rewritten as a final form once all of the other features are implemented.
Overall improvements are benchmarked with minting 100x templated assets, with no mutable or immutable data & 4 schema fields, resulting in:
Table Fetch Improvements
When a table fetch is defined as so:
It makes it so that the table is initialized & stored in memory on every single action call to the contract (including inline actions to itself, such as the logs). Essentially, something like 10x tables are being initialized every single time the contract executes any action, adding an unnecessary overhead to CPU costs.
They have been rewritten to be as so:
Making it so that they are initialized only when the function is called instead of being implicitly initialized, helping mitigate CPU costs. All table fetches have been redefine according to this format.
Collection Data Improvements
All collections' table fetches are consuming (up to) an extra 3kb of on-chain data stored under the 'serialized_data' field, which no smart contract actually needs to interact with. This data is then fetched again during logs, making it so that every 'mintasset' & 'setassetdata' action is fetching (up to) 6kb of unnecessary data.
This upgrade moves the 'serialized_data' to the 'coldata' scope using the same primary_key, as well as implementing automatic conversions to this new approach upon any interaction with a collections' fees, authorized_accounts, notify_accounts or serialized_data.
Further more, 'check_has_collection_auth' has been rewritten to be more CPU performative by not performing a "find" operation on the collections table twice by passing the collection_itr pointer to the function directly
Reference Improvements
Makes the 'check_name_length' & 'check_format' functions operate on data by reference instead of by value, preventing unnecessary copies