-
Notifications
You must be signed in to change notification settings - Fork 64
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
Improve performance of Promise especially in Windows #716
Conversation
The timer_start() is FILO in Vim and FIFO in Neovim. Using Async.Later correct this order to FIFO.
It seems test become fragile. I'll try to fix |
Thank you for adding this.
Would you also confirm that performance regressions don't happen on other platform? |
Let me check this tomorrow or day after tomorrow. I actually need to make another pull request and need to reply to an issue today... |
try | ||
call call('call', remove(s:tasks, 0)) | ||
catch | ||
call s:error_handler() |
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 nulll is set via set_error_handler, v:exception should be raised here.
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.
While the error handling is a safety-net, I've changed behavior to use s:_default_error_handler()
instead when s:error_handler
is v:null
.
It seems reviewdog is not available for now? Anyway ignore the CI failure. |
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.
Looks good for me. Waiting for other reviewers' checks
I'll merge it (at least) once @mattn accepts it. (And review-dog get back.) |
It's in vital.vim now vim-jp/vital.vim#716
🎉 |
|
||
function! s:set_max_workers(n) abort | ||
if a:n <= 0 | ||
throw 'vital: Async.Later: the n must be a positive integer' |
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.
throw 'vital: Async.Later: the n must be a positive integer' | |
throw 'vital: Async.Later: the max_workers must be a positive integer' |
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.
A term n
is used in help as well so I think it's ok to use tern n
here.
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.
The message will be shown for a user, so it is better if the message is articulate.
But I do not request to fix this strongly.
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.
The message will be shown for a user,
I think users don't understand anyway even n
was max_workers
... So I'll keep it at least for now.
Assert Equals(exception, v:null) | ||
Assert Match( | ||
\ messages, | ||
\ '^\nHello World\nfunction .*<SNR>\d\+_throw, line 1', |
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.
This test depends on locale. line
will be a 行
in Japanese locale.
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.
How should I fix this? IMO, we should enforce English during tests like https://github.com/lambdalisue/fern.vim/blob/master/test/.themisrc#L12-L17
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 agree with fixing message locale 😃
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.
Internally, it enqueues a {task} into an internal task queue. Tasks | ||
in the queue will be dequeued and processed by internal workers. The | ||
number of internal workers are gradually increase until all tasks in | ||
the queue are completed or reached to the value of "max_workers". | ||
Once the queue become empty, the number of internal workers are | ||
gradually decrease so that no workers exists at the end. |
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.
What is a reason the workers gradually increase/decrease instead of immediate?
Did you encounter performance issues?
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 first version starts 50 timers at the beginning but sometimes it took more than 10ms in Windows (tests has randomly failed.)
I've relied on
Async.Promise
to make fern.vim but the performance issue occurred in Windows.lambdalisue/vim-fern#57
This PR introduces an event loop and workers to execute tasks. Approx. 20x performance improvement has observed in above plugin.
Regression tests
Summary
Before
After