drupal_load() already has a static to prevent it loading a module more than once, and there's no reason not to use it, so we should use include() there instead of include_once().
Here's how it looks in strace, I included the first request immediately after starting apache to strace it (i.e. with a cold start on PHP-level caches), and the third request (where PHP caches are warmed). As you can see the cached version is considerably cleaner. Also note that with 150 modules installed, the strace output will be 50 times as long as it is here, this is just a cached page.
HEAD:
(first request after restart)
8125 lstat("/home/catch/www/7/modules/dblog/dblog.module", {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8125 lstat("/home/catch/www/7/modules/dblog", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8125 lstat("/home/catch/www/7/modules", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8125 open("/home/catch/www/7/modules/dblog/dblog.module", O_RDONLY) = 11
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8125 mmap(NULL, 6768, PROT_READ, MAP_SHARED, 11, 0) = 0x7fb438363000
8125 stat("/home/catch/www/7/modules/dblog/dblog.module", {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8125 munmap(0x7fb438363000, 6768) = 0
8125 close(11) = 0
8125 lstat("/home/catch/www/7/modules/overlay/overlay.module", {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8125 lstat("/home/catch/www/7/modules/overlay", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8125 open("/home/catch/www/7/modules/overlay/overlay.module", O_RDONLY) = 11
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8125 mmap(NULL, 33497, PROT_READ, MAP_SHARED, 11, 0) = 0x7fb43835c000
8125 stat("/home/catch/www/7/modules/overlay/overlay.module", {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8125 brk(0x7fb4394a2000) = 0x7fb4394a2000
8125 munmap(0x7fb43835c000, 33497) = 0
8125 close(11) = 0
8125 lstat("/home/catch/www/7/modules/system/system.module", {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8125 lstat("/home/catch/www/7/modules/system", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8125 open("/home/catch/www/7/modules/system/system.module", O_RDONLY) = 11
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8125 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8125 mmap(NULL, 138592, PROT_READ, MAP_SHARED, 11, 0) = 0x7fb438312000
8125 stat("/home/catch/www/7/modules/system/system.module", {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8125 brk(0x7fb4394e5000) = 0x7fb4394e5000
8125 brk(0x7fb439525000) = 0x7fb439525000
8125 brk(0x7fb439568000) = 0x7fb439568000
8125 brk(0x7fb4395ab000) = 0x7fb4395ab000
8125 munmap(0x7fb438312000, 138592) = 0
8125 close(11) = 0
(third request)
7904 lstat("/home/catch/www/7/modules/dblog/dblog.module", {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
7904 lstat("/home/catch/www/7/modules/dblog", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
7904 lstat("/home/catch/www/7/modules", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
7904 open("/home/catch/www/7/modules/dblog/dblog.module", O_RDONLY) = 11
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
7904 mmap(NULL, 6768, PROT_READ, MAP_SHARED, 11, 0) = 0x7f954fcdf000
7904 stat("/home/catch/www/7/modules/dblog/dblog.module", {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
7904 munmap(0x7f954fcdf000, 6768) = 0
7904 close(11) = 0
7904 lstat("/home/catch/www/7/modules/overlay/overlay.module", {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
7904 lstat("/home/catch/www/7/modules/overlay", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
7904 open("/home/catch/www/7/modules/overlay/overlay.module", O_RDONLY) = 11
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
7904 mmap(NULL, 33497, PROT_READ, MAP_SHARED, 11, 0) = 0x7f954fcd8000
7904 stat("/home/catch/www/7/modules/overlay/overlay.module", {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
7904 munmap(0x7f954fcd8000, 33497) = 0
7904 close(11) = 0
7904 lstat("/home/catch/www/7/modules/system/system.module", {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
7904 lstat("/home/catch/www/7/modules/system", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
7904 open("/home/catch/www/7/modules/system/system.module", O_RDONLY) = 11
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
7904 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
7904 mmap(NULL, 138592, PROT_READ, MAP_SHARED, 11, 0) = 0x7f954fc8e000
Patch:
(first request after restart)
8020 stat("/home/catch/www/7/modules/dblog/dblog.module", {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8020 lstat("/home/catch/www/7/modules/dblog/dblog.module", {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8020 lstat("/home/catch/www/7/modules/dblog", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8020 lstat("/home/catch/www/7/modules", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8020 open("/home/catch/www/7/modules/dblog/dblog.module", O_RDONLY) = 11
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
8020 mmap(NULL, 6768, PROT_READ, MAP_SHARED, 11, 0) = 0x7fdc6ff67000
8020 munmap(0x7fdc6ff67000, 6768) = 0
8020 close(11) = 0
8020 stat("/home/catch/www/7/modules/overlay/overlay.module", {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8020 lstat("/home/catch/www/7/modules/overlay/overlay.module", {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8020 lstat("/home/catch/www/7/modules/overlay", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8020 open("/home/catch/www/7/modules/overlay/overlay.module", O_RDONLY) = 11
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
8020 mmap(NULL, 33497, PROT_READ, MAP_SHARED, 11, 0) = 0x7fdc6ff60000
8020 brk(0x7fdc71997000) = 0x7fdc71997000
8020 munmap(0x7fdc6ff60000, 33497) = 0
8020 close(11) = 0
8020 stat("/home/catch/www/7/modules/system/system.module", {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8020 lstat("/home/catch/www/7/modules/system/system.module", {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8020 lstat("/home/catch/www/7/modules/system", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8020 open("/home/catch/www/7/modules/system/system.module", O_RDONLY) = 11
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8020 fstat(11, {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
8020 mmap(NULL, 138592, PROT_READ, MAP_SHARED, 11, 0) = 0x7fdc6ff16000
8020 brk(0x7fdc719da000) = 0x7fdc719da000
8020 brk(0x7fdc71a1a000) = 0x7fdc71a1a000
8020 brk(0x7fdc71a5d000) = 0x7fdc71a5d000
8020 brk(0x7fdc71aa0000) = 0x7fdc71aa0000
8020 munmap(0x7fdc6ff16000, 138592) = 0
8020 close(11) = 0
(third request)
7732 stat("/home/catch/www/7/modules/dblog/dblog.module", {st_mode=S_IFREG|0644, st_size=6768, ...}) = 0
7732 stat("/home/catch/www/7/modules/overlay/overlay.module", {st_mode=S_IFREG|0644, st_size=33497, ...}) = 0
7732 stat("/home/catch/www/7/modules/system/system.module", {st_mode=S_IFREG|0644, st_size=138592, ...}) = 0
There is no real change in benchmarks, however http://tag1consulting.com/blog/nfs-drupal-and-realpath-cache - NFS doesn't cache lstat calls at all, also the faster page caching is (like using APC or memcache as a backend, and with other patches in the queue applied) the more chance we have of seeing an improvement in benchmarks with and without this patch, but I don't think that's necessary since this makes sense by itself.
Closed: duplicate
11.0 🔥
base system
It affects performance. It is often combined with the Needs profiling tag.
After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.