This will most likely be affected by the work done in #1858616: Extract generic CacheCollector implementation and interface from CacheArray.
From #1811816: Benchmark node_page_default vs. node view:
_views_fetch_data() is responsible for 65% of the time spent in drupal_static() with just 30% of the calls. Might make sense to use the fast static cache pattern here?
I'm wondering whether it makes sense to have a service which provides the information, so that there is no need anymore for a procedural function and so no drupal_static.
So we should create a caching class of some flavour to basically replace the code in views/includes/cache.inc. This will save us alot of calls to drupal_static etc... For example, at the moment config() is called on every call to views_cache_get, we can easily get around this.
We could also make this a service in the container, so it is easily swappable too. win!
Comment | File | Size | Author |
---|---|---|---|
#39 | vdc-1867782-39.patch | 36.33 KB | damiankloip |
#39 | interdiff.txt | 437 bytes | damiankloip |
#34 | vdc-1867782-34.patch | 36.38 KB | damiankloip |
#32 | interdiff.txt | 991 bytes | damiankloip |
#32 | vdc-1867782-32.patch | 36.39 KB | damiankloip |
Comments
Comment #1
damiankloip CreditAttribution: damiankloip commentedI will work on an initial patch for this. I think it will be good to play around regardless. We can then track any changes to the interface in #1858616: Extract generic CacheCollector implementation and interface from CacheArray as and when we need to.
Comment #2
damiankloip CreditAttribution: damiankloip commentedHere's an initial conversion, in a ViewsDataCache class. I've currently just hacked this into views_fetch_data for now. It still needs work for sure, just putting what I have up for now.
I will work on this some more later. I would like to get this working, then track the above. The patch is not really tested yet!
Comment #3
damiankloip CreditAttribution: damiankloip commentedComment #4
damiankloip CreditAttribution: damiankloip commentedComment #5
damiankloip CreditAttribution: damiankloip commentedThis patch, sorry for the noise.
Comment #6
damiankloip CreditAttribution: damiankloip commentedAdded it to the container, replaced usage of views_fetch_data, removed cache.inc. Haven't done anything with the language parameter yet. This would need to be passed in somehow too.
Comment #7
damiankloip CreditAttribution: damiankloip commentedSorry, that was silly, we can't remove cache.inc!
Comment #9
damiankloip CreditAttribution: damiankloip commentedThat's not too bad, I'll look at this later!
Comment #10
damiankloip CreditAttribution: damiankloip commentedThat should sort most of them...
Comment #11
Fabianx CreditAttribution: Fabianx commentedTagging
Comment #12
Fabianx CreditAttribution: Fabianx commentedx-post
Comment #13
dawehnerAwesome stuff!
It would be possible to just get the views data object once and then use that object.
Inject all the things!
Yeah if we put this into the constructor on the container this information could be used without a special config call.
What about injecting the cache object via the container?
Just in general: is there a reason to not use drupal_alter?
Comment #15
damiankloip CreditAttribution: damiankloip commentedNice, thanks for the initial review, they are some good suggestions.
It now passes in the config factory from the container, Changed the getting of data to use drupal_alter (this was just what was in the current code), Removed the useLanguage flag - so it now always assumes a language, with the langcode being retrieved in the constructor.
Also added your suggestion for the view_ui_field_list() function.
Comment #16
dawehnerGreat improvements!
We should better use ->get($item['table']) to not require to load all of the data all the time.
Comment #17
damiankloip CreditAttribution: damiankloip commentedGood point, I'll work on this in the morning.
Comment #18
damiankloip CreditAttribution: damiankloip commentedMade that change, added some docs.
Comment #19
damiankloip CreditAttribution: damiankloip commentedOK, so tim.plunkett posted a patch (http://drupal.org/node/1635240#comment-6852750) with the views_fetch_data stuff removed, which passed. So I've merged that into here. I've also moved views_cache_*et function into views.module as there are only 2 now, and removed cache.inc :)
Comment #20
damiankloip CreditAttribution: damiankloip commentedOops, fixed the call to the container in EntityReverse class
Comment #21
tim.plunkettA couple nitpicks, but I just fixed them myself. I think @damiankloip said he wanted Berdir to look this over for some benchmarks, so I won't RTBC yet, but I like this patch a lot.
Comment #22
dawehnerThis looks nearly perfect so far!
So there is no need for these two calls anymore
Nitpick: The empty line seems to make more sense in the current code.
Comment #23
dawehnerSo basically tim fixed the stuff already :)
Let's get some proper benchmarking and then RTBC it.
Comment #24
tim.plunkettRestoring tags.
Comment #25
BerdirWe're just switching one function call with another one so it's IMHO ok, but maybe open a follow-up issue to pass this information to the plugins which need it?
We have a bunch of these now but note that this is not really correct, because cache() does it's own object caching, so cache('views_info') and $container->get('cache.views_info') won't return the same object, which can be a problem depending on how the backend is implemented.
I can see that this works differently* than the current design of CacheArray/CacheCollector, wondering if we could use the same interface as that, though. We'll see.
* I haven't followed the original issue which put this in closely, but I do wonder how a cache_set() for each table performs on a site with 400 fields (which means 800+ tables in the views data definition). Wondering if we could do something similar and only store keys for tables that are actually accessed. Different issue, though.
It's actually a CacheBackendInterface now, so should be named $cacheBackend and it's also not views specific in anyway ("the *views* cache bin"). This is the only thing that needs to be fixed I think. Apart from the fact that it doesn't seem to apply anymore :)
__destruct() in the container is a bit problematic and can result in segfaults for frequently used stuff. It seems work in case of CacheArray or the path alias issue but did not work at all for lock/keyvalue.
Help me to get #512026: Move $form_state storage from cache to new state/key-value system in, then we can use the service terminator for this :)
I'll do some profiling once there is a patch that applies :)
Comment #26
damiankloip CreditAttribution: damiankloip commentedThanks alot for the initial feedback!
Sorry about that, I've just rerolled it now. I think #1862344: Combine the Views plugin managers getting committed broke it :)
1. That's a good idea, Created an issue: #1870970: Only get views table data for plugins that need it
2. I just followed suit with how other implementations were doing this in the core container, shall we fix this here or is there another issue to tackle this for all?
3. Yeah, I think I mentioned at the top of the issue, we will see how the CacheCollecter interface comes on then quite probably use that here.
4. Changed property to cacheBackend
5. I will definitely have a look at that issue and help if I can, if you say this will/could be problematic.
Anyway, you should be able to apply this for profiling now :)
Comment #27
damiankloip CreditAttribution: damiankloip commentedOh, you might be needing this too.
Comment #28
damiankloip CreditAttribution: damiankloip commentedComment #30
Berdir#27: vdc-1867782-26.patch queued for re-testing.
Comment #31
Berdir2. There is an own issue: #1764474: Make Cache interface and backends use the DIC.
Performance looks nice! A whole bunch of function calls saved and replaced with much faster ones. See screenshots. Memory usage difference can be ignored I think, not even 0,1%.
@var definition needs to be updated as well, I'd also say cache backend instead of cache bin.
Happy to RTBC once that is fixed.
Comment #32
damiankloip CreditAttribution: damiankloip commentedNice, that is good news! Thanks for doing that. Getting rid of all those include calls is a massive win :)
I have made those changes..
Comment #33
BerdirHm, was the "in" supposed to be "bin"? Because in doesn't make much sense, neither in the old nor new comment...
Comment #34
damiankloip CreditAttribution: damiankloip commentedHAHA, yep. You're right.
Comment #35
BerdirOk, I think this is good to go. Nice little performance improvement and code looks nicer as well.
Testbot needs to agree of course, but the last two patches where just documentation changes.
Comment #36
tim.plunkettAwesome!
Comment #37
olli CreditAttribution: olli commentedOne small confusing change is this
vs
Is that ok?
Comment #38
damiankloip CreditAttribution: damiankloip commentedYes, because if nothing gets set to storage, it will be an array anyway, see the property declarations at the top of the class.
Comment #39
damiankloip CreditAttribution: damiankloip commentedWas just talking to merlinofchaos on IRC, Let's just remove that comment.
Comment #40
olli CreditAttribution: olli commentedOk, thanks. #39 looks brilliant.
Comment #41
webchickI always get a sad face when we remove useful wrapper functions in favour of drupal_container()->some('crap')->that('chains')->forever('and ever') but this is consistent with what we have done elsewhere.
Committed and pushed to 8.x. Thanks!
This will need a change notice, so moving to the Views queue to track that, per Jess.
Comment #42
webchickTitle change.
Comment #43
dawehnerYeah: http://drupal.org/node/1872588
Comment #44
BerdirMe too. My main problem is that those are relatively hard to find (maybe we can fix that with some sort of list of what services core provides, e.g. as a new topic in the api documentation about that whole thing?) and you have absolutely no type hinting in IDE's.
Crell's answer to that is that all that stuff should be injected, but we can only inject when we have services/classes/factories where the calling code knows what will actually be required. While that helps and was my suggestion here as well (which has been slightly misunderstood I think, will comment in the follow-up issue), it is not going to happen in 8.x for most of the code.
Change notice looks ok to me.
Comment #45
yched CreditAttribution: yched commentedIt seems ViewsDataCache::get($key) will return the full array of $this->storage when $this->storage[$key] could not be found ?
It that the intended behavior ? Seems odd DX wise (you get a result in a different format when the key you requested doesn't exist / is invalid ?)
#1863816: Allow plugins to have services injected would help a bit with making more stuff injectable.
Comment #46
damiankloip CreditAttribution: damiankloip commentedYeah, it's a fair point. This patch was just a port of that logic into the new class (basically to remove the cache.inc file). It would probably not be ideal if you provided a base table like 'nobe' instead of 'node' and it returned ALL THE DATA. So you would only get everything if $key was NULL.
Happy to create a follow up issue for this?
Comment #47.0
(not verified) CreditAttribution: commentedUpdated issue summary.