Optimize cache for autoloading classes in haXe/PHP

in

The code generated using haXe/PHP uses the PHP autoloading feature to dynamically load classes definitions when they are required. This method has many advantages but a drawback too; the thing is that the autoloading function (hidden in php.Boot) needs to scan the lib folder to look for type definitions. It is not really a big work since only the file names are read without the need to immediately open the files, nevertheless this work is made each time the page is accessed. To reduce the impact of this operation you can simply create a cache folder at the same level of lib and give it the proper attributes for PHP being able to write files in there. On the next use of your script, a new file haxe_autload.php will be automatically generated and will contain all the info required by the autoloading function.

As you can guess, the impact of this feature is proportional to the number of classes included in your project.

Be warned that it is better to use the cache only on production sites because during development it is quite normal adding new classes and the cache will not include them unless the haxe_autload.php file is manually deleted. If you need to upgrade your production code, remember to delete that file first!

edit: I've made a few informal tests compiling a project that generates 76 files but uses only a few of them to maximize the impact of the cache trick. The results are the following but remember that your mileage may vary greatly and you can also find out that you will not have any benefit from abilitating the cache feature.

Execution time:
198ms no cache
151ms cache activated (31% speed gain)
Related Project(s): 
haXe/PHP