Search code examples
phpperformancememory

Can defining a lot of constants cause performance or memory problems?


I have a website which uses a lot of constants, that are defined like this, for example:

define('CONSTANT', 1)

I currently have a list of about 200 defines like this. This list is run every time a page loads. Is this going to affect my performance or memory use badly?


Solution

  • There are reasons to avoid a list of 200 constants on every page load, but performance and memory usage would not be among them. In general, the best way to answer these kinds of questions is to run benchmarks. Measure page load time and memory usage both with and without loading your 200 constants. Measure a few thousand times and look at the numbers. I suspect you'll find a negligible difference. Micro-optimization is usually a waste of time.