Closed (works as designed)
Project:
Countries
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
8 Jan 2012 at 13:36 UTC
Updated:
6 Jul 2013 at 16:14 UTC
Jump to comment: Most recent file
Comments
Comment #1
webflo commentedComment #2
alan d. commentedNot sure how to test, but if your happy with this feel free to commit.
Comment #3
alan d. commentedThis is one of the two issues left that I would like to push into the latest 7.x-2.x branch. After the dust settles on these two new features, I would like to push out 7.x-2.0 tag.
Comment #4
alan d. commentedI want to push out a release soon, as I just discovered that I was incorrectly using hook_hook_info(). This particular bug could cause significant issues if another module decides to share the same namespace, namely complete loss of functionality in the core country element, thus the continent country widget too.
With no new features really pending, this would be the last foreseen release till the next ISO update, which could be months off. With this in mind, I'll tag it as the first stable 2.x release (7.x-2.0).
So would you be happy if I commit this? Or should I skip this for the time being?
Comment #5
webflo commentedSkip it for now. We need something for 2.1 ;)
Comment #6
alan d. commentedlol, sounds good, it can go with #1458938: Add schema columns properties maybe in a month or three.
There are only 3 users (Me, yourself and pcambra) subscribed to either issue.
Comment #7
johnvAlan, don't forget the silent listeners...
I have this patch in my test system - It doesn't break anything, but I can't see any improvements, either.
Anyway, I just wanted to plug htis issue #1596178: too many calls to DrupalCacheInterface::set() ?, which might be related.
Comment #8
alan d. commentedBefore adding the additional overhead, I think that we should step back and realise that we are effectively handling static data here, so maybe we should follow the KISS policy.
Without hooks to clear on insert,update or delete, and no drupal static, this is by far the simplest and is faster than using cores correct method of country_get_list():
Times are around 7ms for the cache load, and then drop to 0.01ms.
Using the core list, with alters but NO country alter (this hook was removed for testing):
Times were around 9ms and 0.3ms.
Using the core list directly:
Times were around 3ms and 0.2ms.
Comment #9
johnvWhat happens if you remove the static in:
You are now caching the cache... increasing memoryload.
Comment #10
alan d. commentedIn the above code (Drupal 6 style), the variable is calculated once and stored in what you would consider the global function space, like the $GLOBAL array, but different.
The second time the function is called, that value is already set so it is reused rather than recalculated. Thus the 0.01ms response time compared to the 7ms response.
Con: This moves the array into memory (probably happens anyway, and is not that high)
Pros: Fast!
Without that static you would effectively have this running every time:
And the cache_get() would always do a database call.
Comment #11
johnv1. So the static indeed makes sense - I wasn't sure if a cache_get() always does a database call.
2. However, I don't see how/when the new code responds to a change in the countries list, c.q. after a cache refresh.
3. Then about the $filters:
- Would a separate cache per filter make sense? Or will it only increase the static memory. You then might remove the Static in countries_countries_alter() and centralize code. See below code.
- off-topic: the function countries_filter() does an unnecessary recursive call to countries_get_countries(). See code below.
Comment #12
alan d. commentedI was posting the concept only. This would cause tests, et al, to fail at the present state. We would need to flush this cache every time that a country was added, updated or deleted.
The filter thing is required as a workaround for some strange workflow, added a year or so back, so fuzzy with the exact issue it resolved, but it is needed for something, somewhere...
I'm not sure about the benefits of caching individual filters.
Comment #13
alan d. commentedRight, the benchmarking of Entity Cache has thrown up a nasty surprise.
Unaltered:
Loaded in 41.144132614136 ms
Loaded in 0.38695335388184 ms
Entity Cache integration:
Loaded in 754.01496887207 ms
Loaded in 853.12294960022 ms
This is based on going to a node edit page with country fields, with the following code to output the results:
It looks like manual caching is by far the best here.
Tonight (in 10 hours) I'll roll a patch for this, basing this off both language caching of all and enabled countries, as I think johnv has a valid point for caching this subset. I know that I have used the countries module to have only 4 countries enabled before, reducing the load by 4/250th if filtered by this flag. However, caching by the other possible combinations could fill up the cache tables, and will bypass.
Follow on issues, ensure that even disabled countries get rendered when displayed, and moving translation to the load, making the countries i18n widget redundant.
Comment #14
alan d. commentedCompletely manual caching. I dropped the idea of caching individual filters as it made the code a lot messier.
Comment #16
alan d. commentedAnother stab.
Maybe this should be lower in the chain but that would require a custom EntityController :/
Comment #18
alan d. commentedSimpleTest uses curl to do the gets and posts.
This was the reason that these were failing, entity_get_controller('country') within the test methods was a different controller instance and was getting stale data.
Comment #19
alan d. commentedComment #20
alan d. commentedOn standard pages there is absolutely no difference in any method that I tested with any significant statistical result.
Randomly picking 50 nodes with 5 country fields each, had better results:
min mean[+/-sd] median max Total: 1111 1136 11.3 1140 1151 (unaltered) Total: 1133 1143 9.5 1140 1161 (entity cache) Total: 1120 1132 8.0 1133 1146 (drupal_static) Total: 1118 1134 10.4 1133 1150 (drupal_static & direct use of cache results)Node with no country fields
min mean[+/-sd] median max Total: 1102 1137 12.6 1140 1156 Total: 1120 1143 13.3 1142 1178 Total: 1118 1142 13.8 1138 1171 Total: 1120 1141 11.5 1139 1172As such, marking as won't fix unless someone can prove some benefit!!
Comment #21
alan d. commented