-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
[RDY] atomic multi request for async remote plugins #4568
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
Conversation
@@ -607,6 +607,96 @@ Array vim_get_api_info(uint64_t channel_id) | |||
return rv; | |||
} | |||
|
|||
Array vim_multi_request(uint64_t channel_id, Array calls, Error *err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vim_batch_call ?
What's the return format? The general shape looks reasonable. Granular error reporting (eg of the failed assertionwill) help a lot. |
Have not checked thoroughly, but this makes me wonder if anybody out there hasn't looked at msgpack-rpc "transactions" by placing multiple rpc messages in a new message type. |
8ca88b3
to
f5ee768
Compare
Updated. I removed the preassert for now, this already useful in various cases without it, (such as updating multiple bufhl in an async context without causing excessive redraws, or emulating the old behavior of del_var after #5336) and that could be added in a separate PR without breaking existing usages. |
f5ee768
to
f88350e
Compare
e7371f7
to
36caf43
Compare
36caf43
to
67d8737
Compare
@justinmk I'd like to nominate this for 0.1.6, as said this would be able to fix real performance issues in bufhl (ref arakashic/chromatica.nvim#18), and, say implement |
bd2e3f3
to
3b03a31
Compare
|
||
MsgpackRpcRequestHandler handler = msgpack_rpc_get_handler_for(name.data, | ||
name.size); | ||
Object result = handler.fn(channel_id, UINT64_MAX, args, &nested_error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UINT64_MAX
-> NO_RESPONSE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that really, no API function does it yet, but they could use NO_RESPONSE
for the optimization "no response exected, don't bother calculating the return value". A separate flag here is probably the best (to use by eval.c:api_wrapper
also)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So INTERNAL_RESPONSE
is a future advisory flag, it's not used any where yet.
Object result = handler.fn(channel_id, UINT64_MAX, args, &nested_error); | ||
if (nested_error.set) { | ||
// error handled after loop | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is on error result
already freed or NIL
? Otherwise missing clean up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be an invariant, whenever an api function sets an error, the return value should be NIL (or at least non-allocating).
/// with at least three elements: the request name, an array of arguments, and | ||
/// a boolean indicating if the return value should be sent back. | ||
/// | ||
/// @return an array with three elements. The first is the number of calls that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of a validation error an empty array is returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean validation of the multi_request array itself? Then an error is sent back, nothing can be returned.
/// call resulting in an error. The second is an array of return values, for | ||
/// calls when the third boolean flag was set to true. The third is NIL if all | ||
/// calls succeeded. If a call resulted in an error, it is a two-element array | ||
/// with the error code and message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code -> type ?
} | ||
|
||
if (retval) { | ||
ADD(results, result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a call fails but a result should be returned, nothing is put in results
. Is this expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the comlete multi_request is then interrupted, so there is no ambiguity what calls the present elements in results
come from.
|
Updated. An alternative could be |
I think it is RDY, if no one objects against |
I would prefer call_atomic because, I think we should eliminate the arbitrary jargon distinction between "methods " and "functions". It's confusing that we assigned special meaning there. Not all API functions are acting on an object in a meaningful sense, so it's more inside knowledge. (In the tests I have been meaning to rename "meths" to "api" or something like that) |
Well, the object in that case is the nvim instance, but I agree it is a bit internal jargon, so changing back to |
/// be indicated in the return value, see below. | ||
/// | ||
/// @return an array with three elements. The first is the number of calls that | ||
/// where performed without errors. If it is the same as the length of "calls", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't need the first item if we instead always return the results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My other suggestion also does this, but in either case I would then include the index in the error tuple because explicit is better than implicit.
/// | ||
/// @param calls an array of calls, where each call is described by an array | ||
/// with at least three elements: the request name, an array of arguments, and | ||
/// a boolean indicating if the return value should be sent back. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the third item (retval
boolean) be a premature optimization? It would greatly simplify explanation/interface of call_atomic
if we did not make results optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we allready allow invidual calls to drop the return value, seems strange to lose this just because one uses multi-request. But to make bookkeeping simpler we could replace them with NIL so array indexing is consistent.
/// | ||
/// This has two main usages: Firstly, to perform several requests from an | ||
/// async context atomically, i.e. without processing requests from other rpc | ||
/// clients or redrawing or allowing user interaction in between. Note that api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoiding redraws is a really nice feature
👍 I also think we should merge curbufmeths into curbuf so one could |
d113523
to
a7d842a
Compare
Ok, updated. It is probably simpler to make sure that that all methods where the return value is not essential, will not have a heavy return value, like we did for the |
2391f3d
to
f6968dc
Compare
remove unused response_id parameter of handle_nvim_... helpers
Did some more doc adjustments, if no more comments I will merge after tests. |
FEATURES: 0b5a7e4 neovim#4432 API: external UIs can render custom popupmenu c6ac4f8 neovim#4934 API: call any API method from vimscript 31df051 neovim#4568 API: nvim_call_atomic(): multiple calls in a single request b268ba3 neovim#5424 API: nvim_win_get_number(), nvim_tabpage_get_number() e7e2844 has("nvim-1.2.3") checks for a specific Nvim version 522b885 neovim#5295, neovim#5493 `:CheckHealth` checks tmux, terminfo, performance 719dae2 neovim#5384 events: allow event processing in getchar() f25797f neovim#5386 API: metadata: Nvim version & API level 22dfe69 neovim#5389 API: metadata: "since", "deprecated_since" 605e743 Added QuickFixLine highlight group CHANGES: 4af6ec7 neovim#5253 perf: Disable clipboard in do_cmdline() 6e9f329 neovim#5299 perf: Skip foldUpdate() in insert-mode. 9d4fcec neovim#5426 perf: Do not auto-update folds for some foldmethods. eeec0ca neovim#5419 tui: Default to normal-mode cursor shape. FIXES: e838452 neovim#5436 tui: Fix "weird characters" / "bleeding termcodes" 10a54ad neovim#5243 signal_init: Always unblock SIGCHLD. bccb49b neovim#5316 eval.c: Fix memory leak for detached pty job 626065d neovim#5227 tchdir: New tab should inherit CWD. cd321b7 neovim#5292 getcwd(): Return empty string if CWD is invalid. 6127eae shada: Fix non-writeable ShaDa directory handling ca65514 neovim#2789 system(): Respect shellxescape, shellxquote 2daf54e neovim#4874 Restore vim-like tab dragging 0c536b5 neovim#5319 syntax.c: Support bg/fg special color-names. 3c53371 neovim#4972 from justinmk/schedule-ui_refresh 68bcb32 neovim#4789 tui.c: Do not wait for tui loop on teardown. c8b6ec2 neovim#5409 v:count broken in command-line window 6bc3bce neovim#5461 fix emoji display 51937e1 neovim#5470 fix :terminal with :argadd, :argu 79d77da neovim#5481 external UIs: opening multiple files from command-line 657ba62 neovim#5501 rplugin: resolve paths in manifest file 6a6f188 neovim#5502 system('foo &', 'bar'): Show error, don't crash. 1ff162c neovim#5515 os_nodetype: open fd with O_NONBLOCK 2a6c5bb neovim#5450 modeline: Handle version number overflow. 0ade1bb neovim#5225 CI tests now run against Windows!
FEATURES: 0b5a7e4 neovim#4432 API: external UIs can render custom popupmenu c6ac4f8 neovim#4934 API: call any API method from vimscript 31df051 neovim#4568 API: nvim_call_atomic(): multiple calls in a single request b268ba3 neovim#5424 API: nvim_win_get_number(), nvim_tabpage_get_number() e7e2844 has("nvim-1.2.3") checks for a specific Nvim version 522b885 neovim#5295, neovim#5493 `:CheckHealth` checks tmux, terminfo, performance 719dae2 neovim#5384 events: allow event processing in getchar() f25797f neovim#5386 API: metadata: Nvim version & API level 22dfe69 neovim#5389 API: metadata: "since", "deprecated_since" 605e743 Added QuickFixLine highlight group CHANGES: 4af6ec7 neovim#5253 perf: Disable clipboard in do_cmdline() 6e9f329 neovim#5299 perf: Skip foldUpdate() in insert-mode. 9d4fcec neovim#5426 perf: Do not auto-update folds for some foldmethods. eeec0ca neovim#5419 tui: Default to normal-mode cursor shape. FIXES: e838452 neovim#5436 tui: Fix "weird characters" / "bleeding termcodes" 10a54ad neovim#5243 signal_init: Always unblock SIGCHLD. bccb49b neovim#5316 eval.c: Fix memory leak for detached pty job 626065d neovim#5227 tchdir: New tab should inherit CWD. cd321b7 neovim#5292 getcwd(): Return empty string if CWD is invalid. 6127eae shada: Fix non-writeable ShaDa directory handling ca65514 neovim#2789 system(): Respect shellxescape, shellxquote 2daf54e neovim#4874 Restore vim-like tab dragging 0c536b5 neovim#5319 syntax.c: Support bg/fg special color-names. 3c53371 neovim#4972 from justinmk/schedule-ui_refresh 68bcb32 neovim#4789 tui.c: Do not wait for tui loop on teardown. c8b6ec2 neovim#5409 v:count broken in command-line window 6bc3bce neovim#5461 fix emoji display 51937e1 neovim#5470 fix :terminal with :argadd, :argu 79d77da neovim#5481 external UIs: opening multiple files from command-line 657ba62 neovim#5501 rplugin: resolve paths in manifest file 6a6f188 neovim#5502 system('foo &', 'bar'): Show error, don't crash. 1ff162c neovim#5515 os_nodetype: open fd with O_NONBLOCK 2a6c5bb neovim#5450 modeline: Handle version number overflow. 0ade1bb neovim#5225 CI tests now run against Windows!
Based on @ZyX-I:s suggestion #4411 (comment) this allows a rpc client to send a list of requests for evaluation at once. This allows "atomic" execution from an external async context (of course, any request that can lead to the execution of vimscript can and will have side-effects in the middle of executing the multi request). Even if
set_var
anddel_var
is changed to not return the oldvalue as suggested in #4411 the old behavior can be kept by bundling a "get_var" and "set_var" requestTo support simple test-and-set behavior, it is possible to assert the return value of a request and abort the execution. For anything more complicated it is better to inject some vimscript (or lua) and let it do it.
The argument is an array of
[methodname, args, sendreturn{, assertreturn}]
entries.simple example:
It could be possible to do something like first
and then
So that the update to the buffer is only done if the buffer was unchanged. The first return value is the number of successful request to this condition can be detected.
Bikeshed of the api and return format welcome. It is quite-low level, but the intention is mainly for client/hosts implementations that can export nicer APIs like
list.pop
anddict.pop
in the case of python, to plugins.