Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

PHP has copy-on-write semantics for strings and arrays -- your sort of reference optimizations seem a little strange to me. That is, unless you're not intending to making copies of structures when you change them inside of functions, in that case using references is not a strange optimization but just the correct choice.


I know PHP uses COW, so theoretically, reading from a variable should have no impact on memory usage whatsoever. This has not proven to be the case, I've called get_peak_memory_usage() and played with passing the params explicitly by reference or not. I assume it has something to do with the fact that strings/arrays are not passed by reference, and explicitly declaring the reference is cheaper sometimes and more expensive sometimes depending on refcount(maybe?)


I'm not entirely sure how much I'd trust get_peak_memory_usage() for this kind of debugging. I'd be more inclined to profile this with xdebug before making these kinds of code changes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: