Skip to content

Remove Manifest Clone in ContractState#1326

Closed
eryeer wants to merge 2 commits intoneo-project:masterfrom
eryeer:pr_optimse_CountractState
Closed

Remove Manifest Clone in ContractState#1326
eryeer wants to merge 2 commits intoneo-project:masterfrom
eryeer:pr_optimse_CountractState

Conversation

@eryeer
Copy link
Copy Markdown
Contributor

@eryeer eryeer commented Dec 5, 2019

After performance testing, we found that when the NEO / GAS transfer transaction was executed in the block Persist, the average time was 0.3ms, and about 0.1-0.2ms of it was spent on the Clone() of the ContractState Manifest. The Clone() is invoked by engine.Snapshot.Contracts.TryGet() of InteropService Contract_Call

ContractManifest currentManifest = engine.Snapshot.Contracts.TryGet(engine.CurrentScriptHash)?.Manifest;

Since Contracts is a CloneCache, when calling TryGetInternal(), the ContractState will clone another copy including the Manifest as well.

Considering that Manifest will not be modified if the snapshot is not committed, and the transaction is executed sequentially, so if the Manifest is used in the transaction execution process, it will not interfere with each other. So consider removing Clone() to improve speed.

@eryeer eryeer changed the title Remove Manifest clone in ContractState Remove Manifest Clone in ContractState Dec 5, 2019
Copy link
Copy Markdown
Member

@erikzhang erikzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public static readonly uint Neo_Contract_Update = Register("Neo.Contract.Update", Contract_Update, GetDeploymentPrice, TriggerType.Application);

The SYSCALL Neo.Contract.Update can update the manifest of the contract. So we can't remove the Clone().

@Tommo-L
Copy link
Copy Markdown
Contributor

Tommo-L commented Dec 5, 2019

If only replace the reference of Contract.Manifest, I think it will be correct without deep copy.

Only when the fields of manifest were modified, we need deep copy to protect the original data.

@erikzhang
Copy link
Copy Markdown
Member

Please test #1328 to check if it has been optimized.

@eryeer eryeer closed this Dec 5, 2019
@eryeer eryeer deleted the pr_optimse_CountractState branch December 24, 2019 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants