-
-
Notifications
You must be signed in to change notification settings - Fork 988
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
Filter refactor #1906
Filter refactor #1906
Conversation
dad4e6a
to
9154010
Compare
Ok Now that i was able to configure my fork to run appvveyor builds, i was able to benhmark this and it does really increase performance, testing code:
running for example a simple Of course this code only really increases performance if the filter is creates once and then run many times, so in order to make this trul useful we should:
|
5f84db5
to
6a1055e
Compare
Let's get this in for 1.13.9. |
I also wanted to do the same for location filter, but that is far more diffucult (due to many other mor or less useful optimisations in that file), my new plan on how to handle terrain filter is to make the engine less guessing on what would be more efficient, and instead add a new terrain filter tag
would then just check for every loction for every adjacent loction whether it matches
would first cache all water tiles and then chesh for each tile wheterh it is ajacent to one of those just cached. |
Okay, so from my initial read-through, I have three comments:
I feel like there was another thing, but if so, I forgot it. Also, I'd like it if you can give an overview of how the new system works. EDIT: Also, I'm not sure I like the |
Basically filter objects have a vector<unique_ptr<abstract_filter>> and for each attribute in the filter a correspsiong abstract_filter-subclass instance is added to that vector,
I think i did it exactly the same way as it was implemented before, |
I mean, maybe |
Note that there currently is no more efficient way to get a unit by id (which is what the variabel contains), even wensoth.get_unit(id) does simply iterate though all units and checks whether it matches the given id, so i don't think your suggestion would increase performance. Anyways i'm still more wrried abotu the terrain filter now, not sure how to handle it. |
Another interesting thing i found out is that using variables inside filters does have a noticable impact on performance, here the results (a variable
Note how even with the old method the filter with the variables takes nearly twice as long asthe one without the variable (16 ticks longer), and even with the new method it takes 7 ticks longer than without. |
Could we add a more efficient way to get a unit by id? |
we could add a map unit id -> underlying id in the unit map structure, but it'd also need to be updated which woudl make the unit_map code more cmplicated and also require some cputime to update it, not sure whether that'd be a noticable optimisation in total, so for now i probalby won't do it. |
Fine, but could you at least rename all the
Okay sure, but what does that have to do with
Umm... you have a strange definition of "noticeable". I highly doubt the user would notice 16 ticks, let alone 7 ticks. Sure, if there are a lot of variables and the delays build up, it could become noticeable, but... |
I could but it's currently not my priority.
The list is a list of unit ids, in order ot get the units objects form those ids you need to do what wesnto,get_unit does. |
Pretty sure the list is typically an array of stored units, not just their IDs. (Admittedly, there may be cases where people took advantage of the fact that the game only tested the ID.) |
Creating units form the variable woudl sureley be much slower than looing it up by the id, so i don't see how that'd matter here, |
Technically you wouldn't have to create actual units from the config in order to determine if it matches the filter... but whatever. |
ok, i just tested again, and was suprised that this even (although marginally, from 0.532 to 0.433 ticks ) speedsup filter for filters that are just run once. (tested with a simple |
Why is this PR all messed up suddenly? Did you merge master in rather than rebasing? |
i did a |
65f7b50
to
28e43da
Compare
hmm now i did a |
28e43da
to
a1931e8
Compare
Oh right, could you please rename all the |
1a5627d
to
c93369b
Compare
ff883cd
to
472d267
Compare
This refactors the unit filter so that it now parses as much as possible when the filter is created to speed up the filter::matches function. This also make the provious optimisation of having a special empty filter unnecessary.
I checked all codes that construct side filters but i couldn't find a single occurance where the side filter object lived longer than the underlying config object. (there were occurances in terrain_filter/side_filer where i was not sure so i added an extra make_safe there). Feels a littlte strange since there should've been a reason why that make_safe call was added in the first place.
by (notepad++) regex replace `u\.(use_flat_tod|u2|fc|u|loc)([^a-zA-Z1-9])` to `args\.\1\2`
472d267
to
d2de54d
Compare
This refactors the unit filter so that it now parses as much as possible when the filter is created to speed up the filter::matches function. This also make the provious optimisation of havign a 'nil' filter unnecessary.
Also i did comepletey reworite these files so looking at the diff probably won't be handy.