php - Why is including multiple files so much slower than bundling into one -
i have been doing tests php, , have noticed performing include
on multiple files compare 1 containing functions slower.
my test involved creating 1025 files, 1024 of contained text <?php class cls$i {} ?>
(where $i file number), , 1 file concatenation of text in files before. had 2 functions, 1 testing each case. test loaded single file took 6ms
compile bytecode , make contents available system, however, combination of 1024 files took 600ms
.
in terms of size, 1024 individual files same size single file. running apc
cache bytecode, in practice, shaves off few milliseconds.
i created ramdisk held files, marginally (10ms on average) faster.
so, having said that, why individual files sooooo slower single file? down significant inefficiencies in loading engine within php, or have made considerable cockup in configuration (on local system, standard ampps installation)?
my first guess it's stat
system calls going on.
what happens if turn apc.stat
off in config?
even though apc caches bytecode, if apc.stat=1
, needs check mtime on each file via filesystem make sure doesn't need re-read.
edit: going deeper, in response comment. how referencing included files? if you're using relative paths, you're getting include_path involved.
in other words:
include "somefile.php";
is slower than
include __dir__ . '/otherfile.php';
Comments
Post a Comment