set_task with B flag - replace with entity think API?
Has anyone thought about doing this before? It sounds like a general optimization.
Create one plugin that creates an entity with think set to .1 seconds, then other plugins would use the API to add their set_tasks with "b" flag to the entity's think. Check for tasks registered in it and if it's time to call one, execute a function in the plugin that registered the task. What do you think? If it's not a bad idea and can be at least a bit useful, I could try to come with something. Not sure how to execute a function in other plugin though and callfunc_x looks really slow. |
Re: set_task with B flag - replace with entity think API?
Something like that :
- Main Plugin - PHP Code:
PHP Code:
|
Re: set_task with B flag - replace with entity think API?
It's a very bad idea. You want to replace a system coded and optimized in C with a system code in Pawn ? It will be way slower and inefficient. Also, thinking each 0.1 seconds it's what does basically the code for set_task. Using set_task with "b" flag is fine.
|
Re: set_task with B flag - replace with entity think API?
Well yeah but it will only be done once, if you use 5 plugins with set_task and "b" flag for .1 seconds it's going to create 5 tasks, where as using that will still use only 1 think.
|
Re: set_task with B flag - replace with entity think API?
It creates 5 tasks and what ? It changes nothing really.
The code for set_task works like that : AMXX hooks ServerFrame, does a check so the set_task code is executed each 0.1 second, then this code loops on all registered tasks. 5, 10, 15 tasks, you won't see any significant changes. All checks and such are done in the module, it's optimized and fast. Your way to use a global think, could be useful only if you need to use a think for 0.1 second _only_ in several plugins, so you would save entities. That's only the advantage I can see. |
Re: set_task with B flag - replace with entity think API?
Okay, thanks for the explanation. Now that I think of it, calling the function directly from the main plugin could be actually even slower.
|
Re: set_task with B flag - replace with entity think API?
I would say that, unless you need something to think < 0.1 or you need an entity to something specific, you should avoid creating entity when it's not necessary, because of all the code involving behind the creating/handling of an entity in the engine VS a simple loop with some check, which is not worth.
|
Re: set_task with B flag - replace with entity think API?
I started to code module a while ago that replaces set_task with optimized version that uses single thinking entity and custom data structures instead of STL, but it's still unfinished.
From what I remember a task running with "b" flag is not that cpu expensive, but the most expensive operation is creating task and the time required to do it rises significantly with increasing amount of tasks running across all plugins. I did some tests on machine with 2GHz athlon xp and the results were: Creating 50k tasks with default set_task takes 159 sec. The cpu usage while tasks are running is: 38%-40% Creating 50k tasks with my module takes less than 1 sec. The cpu usage while tasks are running is: 33%-36% |
Re: set_task with B flag - replace with entity think API?
That's awesome, are you going to continue working on it?
|
Re: set_task with B flag - replace with entity think API?
Yes, I will try to finish it soon, since there is no point in anyone starting to code this when I already have working version with some details left to code. At first I tried to do it with a plugin like you suggested in your first post, but as Arkshine said that was wrong way (inter plugin communication made it very inefficient).
|
| All times are GMT -4. The time now is 08:17. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.