refactor: use gstd::message_loop only for async ctors and service methods#939
Merged
refactor: use gstd::message_loop only for async ctors and service methods#939
gstd::message_loop only for async ctors and service methods#939Conversation
vobradovich
reviewed
May 30, 2025
Contributor
Author
|
By the b3eb14 it was agreed to implement sync |
try_handle if service has no async methodsgstd::message_loop only for async ctors and service methods
vobradovich
requested changes
Jun 12, 2025
vobradovich
approved these changes
Jun 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #63
The PR suggests not using async runtime from the
gstdby default for any message sent to program. The separation between calls that require async runtime and sync execution was benched (see comments below) and it was concluded that the separation saves 100-200kk of gas. The changes in code generation are the following:InvocationIotrait now hasASYNCconstant.serviceandprogrammacros define theASYNCvalue for each constructor and service method that implementsInvocationIo.check_asyncnessmethod that accepts encoded service method route and params and returns whether the method is async. Basically, returnsASYNCconst of theInvocationIoimplementor.servicemacro now generates 2try_handlemethods:try_handleandtry_handle_async. The former invokes sync method, and the latter - async ones. Methods also calltry_handle*methods of base services.CommandsandQuerieshasASYNCconst in their impl items. By default, theASYNCisfalse. If there are any commands and queries, theirInvocationIo::ASYNCvalues will be used.ServiceMetatrait now also hasASYNCconstant. The value is generated fromCommands::ASYNC,Queries::ASYNCandASYNCvalues of base services, which also implement theServiceMetatrait.ConstructorsMetanow also hasASYNCconstant in its impl item. The value of the constant is defined byInvocationIo::ASYNCof constructors (params structs).programmacro never usesgstd::async_initorgstd::async_main. Instead generates plaininit,handle,handle_replyandhandle_signal.initmethod invokes constructors. If a constructor is an async, thengstd::message_loopwill be used. Otherwise a simple sync constructor call will be generated.ProgramMetatrait now also hasASYNCconstant. It's value is defined fromConstructorsMeta::ASYNCandServiceMeta::ASYNCof programs services. All in all it's a logical operation where each operand is anASYNCvalue for each constructor and service method (params struct)handle_signalis always generated except for cases whenethexefeature is onhandle_replyis always generated. Both inhandle_replyandhandle_signalhooks fromgstdare called only ifProgramMeta::ASYNCvalue istrue. The latter means that there's somewhere in programgstd::message_loopis used for async methods execution. So due to the fact that async methods are fromgstdand thewait/wakelogic is already handled by hooks ingstd, these hooks must be used inhandle_replyandhandle_signalto implement proper async/await experience for developers.ethexefeature there are several corresponding changes:try_handle_solidityandtry_handle_solidity_asyncare also implemented pretty same astry_handle*match_ctor_solidityis now a sync function that in case the constructor is async, invokes it insidegstd::message_loop.TODO:
̶e̶x̶a̶m̶p̶l̶e̶s̶̶ ̶(̶a̶n̶d̶ ̶̶e̶t̶h̶e̶x̶e̶̶)̶ (UPD: done)