Home Download Buy Blog Forum Support

Best and most efficient way to perform a deferred action

Re: Best and most efficient way to perform a deferred action

Postby tito on Sat May 17, 2014 3:56 am

I'm not sure how Lock works.. I can't help there.. but if that block the main thread, then I'll avoid it. Setting a flag should really just works. I'm witness btw, of the performance of complex and handy BH :)
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 855
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: Best and most efficient way to perform a deferred action

Postby facelessuser on Sat May 17, 2014 4:41 am

tito wrote:I'm not sure how Lock works.. I can't help there.. but if that block the main thread, then I'll avoid it

In this scenario, you can see I haven't been too concerned about it because I am not using them :); BH works well enough. It is just a way to make things thread safe. Two threads accessing the same data can sometimes cause problems (not so much for read only data). If I was serious, I would just have to make sure where I need thread safety. Keep in mind I don't claim to be a threading expert either. I was more just admitting that what I use isn't perfect, but it works well enough.
facelessuser
 
Posts: 1574
Joined: Tue Apr 05, 2011 7:38 pm

Re: Best and most efficient way to perform a deferred action

Postby FichteFoll on Sun May 18, 2014 5:22 pm

tito wrote:Imagine.. you are going to "tint" the gutter if the line you are on, is marked as modified by your.. VCS.. you call.. run() .. imagine it takes 1 second to resolve if the line has been modified... and you execute "run" 4 time per second.. you have 4 running "runs"... The suggested implementation should track if the process is running before trying to running it again, as in item1


I think that you don't know how exactly threads in the threading module work. You should check the docs for that.

The run() method is only run once, when I invoke `start()`. I then do the processing there and only there so the task itself can only run once at a time - as long as I don't create another thread and run the `poke` method on it.

I do agree that resetting the timer once the task itself has finished might be useful at times, but this is dependant on the action and can be added later if necessary.
FichteFoll
 
Posts: 388
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: Best and most efficient way to perform a deferred action

Postby tito on Mon May 19, 2014 1:28 am

The original question to the thread was, "Best and most efficient way to perform a deferred action" and that also include to keep track if things are still running. In you quote, I was refering to GitGutter that slowed down the app considerable because of the problem I described in the previous post.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 855
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: Best and most efficient way to perform a deferred action

Postby tripshock on Sun Jun 01, 2014 11:16 pm

Thanks for the input, everyone. facelessuser's method is something I've seen a few plugins employ, and seems to be the best solution available.

I do think though that this should be something natively available as part of the API, because:
  1. It's something that is commonly needed.
  2. It's something that is hard to get right, and there are bad implementations out there.
  3. It can probably be implemented very efficiently natively.
Might be something for the developers to consider.
tripshock
 
Posts: 7
Joined: Fri Aug 02, 2013 12:21 am

Re: Best and most efficient way to perform a deferred action

Postby FichteFoll on Mon Jun 02, 2014 1:48 am

tripshock wrote:I do think though that this should be something natively available as part of the API, because:
  1. It's something that is commonly needed.
  2. It's something that is hard to get right, and there are bad implementations out there.
  3. It can probably be implemented very efficiently natively.


1. I have written several plugins and didn't need it once. You are right in that this is a reoccurring problem, but I wouldn't say it's common.
2. I agree with that, but so are many other things. And maybe you want to implement it differently? You already saw three different solutions, each with their own (more or less) advantages and suitable for different needs. And now imagine how many other potentially useful code snippets there might be. Should a software with a powerful scripting language like Python really provide some random snippets for each possible use case? I think not. The "_async" are a great example of a useful abstraction of a common use case but this here is not as easily applicable.
3. See 2.
FichteFoll
 
Posts: 388
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Previous

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 8 guests