The date object creation of time integers in office_hours_field_formatter_view() takes a lot of resources. These integers often repeat themselves as well. For example stores usually open and close at the same hours.

In it's current state these function calls would render the module unusable on a site displaying lots of office hours, eg. in a google map which is my use case.

Comments

oxyc’s picture

Status: Needs review » Active
StatusFileSize
new21.53 KB
new21.25 KB
new2.42 KB

I haven't tested this in production yet and I don't know if this will be enough but at least it's a good start.

This patch statically caches the object creation per time integer. Additionally it caches the current time across a page request so nothing unwanted happens. I'm far from familiar with date logic so someone with more experience should definitely RTBC this, it might need some more work.

XHPRof for a request displaying 3 entities with office hours.

Before:
before.png

After:
after.png

oxyc’s picture

Status: Active » Needs review
johnv’s picture

Status: Active » Needs review
StatusFileSize
new4.21 KB

What are your figures when using this version (removing the expensive DateTime class alltogether)?

oxyc’s picture

Sorry for taking so long in testing this! I appreciate you looking into it.

Single entity with office hours:

Original:
Total Incl. Wall Time (microsec): 749,925 microsecs
Total Incl. CPU (microsecs): 740,046 microsecs
Total Incl. MemUse (bytes): 85,551,696 bytes
Total Incl. PeakMemUse (bytes): 85,807,080 bytes
Number of Function Calls: 41,050

Patch from #1:
Total Incl. Wall Time (microsec): 673,621 microsecs
Total Incl. CPU (microsecs): 668,041 microsecs
Total Incl. MemUse (bytes): 85,601,408 bytes
Total Incl. PeakMemUse (bytes): 85,857,312 bytes
Number of Function Calls: 34,946

Patch from #3:
Total Incl. Wall Time (microsec): 622,382 microsecs
Total Incl. CPU (microsecs): 616,039 microsecs
Total Incl. MemUse (bytes): 85,381,328 bytes
Total Incl. PeakMemUse (bytes): 85,636,736 bytes
Number of Function Calls: 32,853

10 entities with office hours (all displaying the exact same hours):

Original:
Total Incl. Wall Time (microsec): 1,938,972 microsecs
Total Incl. CPU (microsecs): 1,920,121 microsecs
Total Incl. MemUse (bytes): 111,618,320 bytes
Total Incl. PeakMemUse (bytes): 112,303,584 bytes
Number of Function Calls: 183,432

Patch from #1:
Total Incl. Wall Time (microsec): 1,418,715 microsecs
Total Incl. CPU (microsecs): 1,364,086 microsecs
Total Incl. MemUse (bytes): 111,646,480 bytes
Total Incl. PeakMemUse (bytes): 112,332,112 bytes
Number of Function Calls: 103,771

Patch from #3:
Total Incl. Wall Time (microsec): 1,296,370 microsecs
Total Incl. CPU (microsecs): 1,280,080 microsecs
Total Incl. MemUse (bytes): 111,457,936 bytes
Total Incl. PeakMemUse (bytes): 112,142,336 bytes
Number of Function Calls: 101,462

Just for frame of reference, not displaying the office hours field on the 10 entities:
Total Incl. Wall Time (microsec): 1,296,770 microsecs
Total Incl. CPU (microsecs): 1,280,080 microsecs
Total Incl. MemUse (bytes): 111,273,056 bytes
Total Incl. PeakMemUse (bytes): 111,928,064 bytes
Number of Function Calls: 97,569

johnv’s picture

Cool! Thanks for testing and your ideas! I'll add #3 shortly.

johnv’s picture

Status: Needs review » Fixed

Committed here.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Added actual description