Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCA: batch internal calls #1303

Closed
wants to merge 3 commits into from
Closed

Conversation

alexytsu
Copy link
Contributor

@alexytsu alexytsu commented May 25, 2023

WIP for #1278

A preliminary attempt at batching some of the internal calls of PCA in order to reduce gas usage. The code factoring is in need of improvement but this is just an early attempt to see the impact of batching multiple calls into one. This PR introduces batchy versions of:

  • Market::ActivateDeals
  • Registry::ClaimAllocations

The initial traces show a ~7-10% reduction in gas usage when a batch of 8 sectors are proved together. Which can be seen here

The total message cost goes down even less ~5%. There's may be internal optimisations to make the batchy methods more efficient but simply batching the method calls seems to only have a smallish effect.

@alexytsu alexytsu force-pushed the alexytsu/pca-improvements-batching branch from 3261bf8 to 78029ed Compare May 25, 2023 01:34
@alexytsu
Copy link
Contributor Author

alexytsu commented May 25, 2023

The branch on anorth/fvm-workbench used to profile this: filecoin-project/fvm-workbench#12

@alexytsu alexytsu force-pushed the alexytsu/pca-improvements-batching branch from 5f53d85 to f67f5b2 Compare May 25, 2023 12:47
@alexytsu
Copy link
Contributor Author

alexytsu commented May 25, 2023

Collapsing the DataCap::Burn operations into one call is a more significant improvement on the total gas cost. With all three calls made batchy, the total saving is around 15%.

Span[Root, self: {sum=0, none=0}, total: {sum=279,543,986, OnVerifyAggregateSeals=115,956,010, OnBlockLink=83,177,016, wasm_exec=38,651,873, OnBlockOpenBase=27,366,240, OnSyscall=9,156,000, wasm_memory_init=3,145,728, OnMethodInvocation=525,000, OnActorUpdate=475,000, OnBlockOpenPerByte=359,610, OnGetRandomness=344,160, wasm_memory_grow=209,716, OnBlockCreate=147,270, OnBlockRead=14,942, OnHashing=9,422, OnValueTransfer=6,000, OnGetBuiltinActorType=0, none=0, OnBlockStat=0, OnNetworkContext=0, OnSelfBalance=0, OnMessageContext=0, OnGetActorCodeCid=0}]
Span[1-Call(102->f2gmwicvcjm37wudcg6giiha37thwguhswilekszy::26), self: {sum=174,815,498, OnVerifyAggregateSeals=115,956,010, OnBlockLink=22,199,335, wasm_exec=20,724,879, OnBlockOpenBase=11,246,400, OnSyscall=3,038,000, OnActorUpdate=475,000, wasm_memory_init=471,860, OnGetRandomness=344,160, OnBlockOpenPerByte=178,100, OnMethodInvocation=75,000, wasm_memory_grow=52,429, OnBlockCreate=46,790, OnBlockRead=7,425, OnHashing=112, OnGetActorCodeCid=0, OnSelfBalance=0, OnBlockStat=0, OnNetworkContext=0, OnMessageContext=0, OnGetBuiltinActorType=0}, total: {sum=279,543,986, OnVerifyAggregateSeals=115,956,010, OnBlockLink=83,177,016, wasm_exec=38,651,873, OnBlockOpenBase=27,366,240, OnSyscall=9,156,000, wasm_memory_init=3,145,728, OnMethodInvocation=525,000, OnActorUpdate=475,000, OnBlockOpenPerByte=359,610, OnGetRandomness=344,160, wasm_memory_grow=209,716, OnBlockCreate=147,270, OnBlockRead=14,942, OnHashing=9,422, OnValueTransfer=6,000, OnNetworkContext=0, OnMessageContext=0, OnSelfBalance=0, OnGetBuiltinActorType=0, OnGetActorCodeCid=0, OnBlockStat=0}]
Span[2-Call(105->f02::3), self: {sum=1,002,897, wasm_memory_init=445,645, OnBlockOpenBase=187,440, wasm_exec=154,751, OnSyscall=112,000, OnMethodInvocation=75,000, wasm_memory_grow=26,215, OnBlockOpenPerByte=1,170, OnBlockCreate=630, OnBlockRead=47, OnGetBuiltinActorType=0, OnGetActorCodeCid=0, OnMessageContext=0}, total: {sum=1,002,897, wasm_memory_init=445,645, OnBlockOpenBase=187,440, wasm_exec=154,751, OnSyscall=112,000, OnMethodInvocation=75,000, wasm_memory_grow=26,215, OnBlockOpenPerByte=1,170, OnBlockCreate=630, OnBlockRead=47, OnMessageContext=0, OnGetBuiltinActorType=0, OnGetActorCodeCid=0}]
Span[3-Call(105->f04::9), self: {sum=982,221, wasm_memory_init=445,645, OnBlockOpenBase=187,440, wasm_exec=133,812, OnSyscall=112,000, OnMethodInvocation=75,000, wasm_memory_grow=26,215, OnBlockOpenPerByte=1,500, OnBlockCreate=550, OnBlockRead=60, OnGetActorCodeCid=0, OnMessageContext=0, OnGetBuiltinActorType=0}, total: {sum=982,221, wasm_memory_init=445,645, OnBlockOpenBase=187,440, wasm_exec=133,812, OnSyscall=112,000, OnMethodInvocation=75,000, wasm_memory_grow=26,215, OnBlockOpenPerByte=1,500, OnBlockCreate=550, OnBlockRead=60, OnGetActorCodeCid=0, OnGetBuiltinActorType=0, OnMessageContext=0}]
Span[4-Call(105->f05::295558876), self: {sum=43,417,838, OnBlockLink=22,402,344, OnBlockOpenBase=8,997,120, wasm_exec=8,617,718, OnSyscall=2,688,000, wasm_memory_init=445,645, OnBlockOpenPerByte=116,230, OnMethodInvocation=75,000, OnBlockCreate=35,980, wasm_memory_grow=26,215, OnHashing=8,904, OnBlockRead=4,682, OnNetworkContext=0, OnGetBuiltinActorType=0, OnMessageContext=0, OnBlockStat=0, OnGetActorCodeCid=0}, total: {sum=43,417,838, OnBlockLink=22,402,344, OnBlockOpenBase=8,997,120, wasm_exec=8,617,718, OnSyscall=2,688,000, wasm_memory_init=445,645, OnBlockOpenPerByte=116,230, OnMethodInvocation=75,000, OnBlockCreate=35,980, wasm_memory_grow=26,215, OnHashing=8,904, OnBlockRead=4,682, OnGetBuiltinActorType=0, OnMessageContext=0, OnBlockStat=0, OnGetActorCodeCid=0, OnNetworkContext=0}]
Span[5-Call(105->f06::1455686749), self: {sum=53,901,018, OnBlockLink=36,085,142, wasm_exec=8,390,062, OnBlockOpenBase=5,998,080, OnSyscall=2,758,000, wasm_memory_init=445,645, OnMethodInvocation=75,000, OnBlockCreate=60,400, OnBlockOpenPerByte=59,490, wasm_memory_grow=26,215, OnBlockRead=2,593, OnHashing=392, OnGetBuiltinActorType=0, OnGetActorCodeCid=0, OnMessageContext=0, OnBlockStat=0, OnNetworkContext=0}, total: {sum=56,837,168, OnBlockLink=37,532,954, wasm_exec=8,743,786, OnBlockOpenBase=6,372,960, OnSyscall=2,968,000, wasm_memory_init=891,290, OnMethodInvocation=150,000, OnBlockCreate=61,720, OnBlockOpenPerByte=60,980, wasm_memory_grow=52,429, OnBlockRead=2,659, OnHashing=392, OnGetBuiltinActorType=0, OnGetActorCodeCid=0, OnBlockStat=0, OnMessageContext=0, OnNetworkContext=0}]
Span[6-Call(6->f07::1434719642), self: {sum=2,936,151, OnBlockLink=1,447,812, wasm_memory_init=445,645, OnBlockOpenBase=374,880, wasm_exec=353,724, OnSyscall=210,000, OnMethodInvocation=75,000, wasm_memory_grow=26,215, OnBlockOpenPerByte=1,490, OnBlockCreate=1,320, OnBlockRead=66, OnBlockStat=0, OnMessageContext=0}, total: {sum=2,936,151, OnBlockLink=1,447,812, wasm_memory_init=445,645, OnBlockOpenBase=374,880, wasm_exec=353,724, OnSyscall=210,000, OnMethodInvocation=75,000, wasm_memory_grow=26,215, OnBlockOpenPerByte=1,490, OnBlockCreate=1,320, OnBlockRead=66, OnBlockStat=0, OnMessageContext=0}]
Span[7-Call(105->f04::6), self: {sum=2,482,366, OnBlockLink=1,042,384, wasm_memory_init=445,645, OnBlockOpenBase=374,880, wasm_exec=276,930, OnSyscall=238,000, OnMethodInvocation=75,000, wasm_memory_grow=26,215, OnBlockOpenPerByte=1,630, OnBlockCreate=1,600, OnBlockRead=70, OnHashing=14, OnGetActorCodeCid=0, OnGetBuiltinActorType=0, OnBlockStat=0, OnMessageContext=0}, total: {sum=2,482,366, OnBlockLink=1,042,384, wasm_memory_init=445,645, OnBlockOpenBase=374,880, wasm_exec=276,930, OnSyscall=238,000, OnMethodInvocation=75,000, wasm_memory_grow=26,215, OnBlockOpenPerByte=1,630, OnBlockCreate=1,600, OnBlockRead=70, OnHashing=14, OnGetActorCodeCid=0, OnMessageContext=0, OnBlockStat=0, OnGetBuiltinActorType=0}]
Span[8-Call(105->f099::0), self: {sum=6,000, OnValueTransfer=6,000}, total: {sum=6,000, OnValueTransfer=6,000}]

The larger saving here might be expected as batching the burns collapses 8 state operations into one. On the other hand, batching Market::ActivateDeals and Registry::ClaimAllocations reduces message overheads but doesn't necessarily save much on actual state operations without a more invasive refactor.

@anorth anorth force-pushed the anorth/pca-integration-test branch 3 times, most recently from f18e21f to c03e1a3 Compare May 25, 2023 23:33
@alexytsu alexytsu force-pushed the alexytsu/pca-improvements-batching branch from f67f5b2 to fa6ddc6 Compare May 26, 2023 00:25
Base automatically changed from anorth/pca-integration-test to master May 26, 2023 01:29
@alexytsu alexytsu force-pushed the alexytsu/pca-improvements-batching branch from 47f4057 to 9dd24d3 Compare May 26, 2023 02:22
@alexytsu alexytsu force-pushed the alexytsu/pca-improvements-batching branch from 9dd24d3 to 43923d2 Compare May 29, 2023 06:37
@alexytsu alexytsu closed this Jun 8, 2023
@alexytsu alexytsu deleted the alexytsu/pca-improvements-batching branch July 27, 2023 06:57
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.

1 participant