107
submitted 1 year ago* (last edited 1 year ago) by kovalensky@lemmygrad.ml to c/programmerhumor@lemmy.ml

2020 study pdf.

After seeing this a couple years ago I started to be more responsible for my PHP code, writing it even with the slightest micro-optimizations possible, since more times people use my code (especially due to nature of PHP being executed in every http request), more energicity they waste because of my lazyness and more they pollute the planet. JIT was NOT included in this experiment, so the number can be much more lower.

I hope you will be responsible for your code so on too (generally I mean people using interpreted languages).

you are viewing a single comment's thread
view the rest of the comments
[-] sim642@lemm.ee 12 points 1 year ago

Or you could just write your backend in JS and save a lot according to this table.

The big inefficiency of PHP is that every request is handled in a new instance as opposed to one process running the server continuously.

[-] kovalensky@lemmygrad.ml 9 points 1 year ago* (last edited 1 year ago)

That actually depends on the type of a server.

Common PHP-FPM for example allows for persistent PHP processes to handle multiple requests, reducing the overhead of creating a new instance for each request.

Also then there was no stable JIT while doing this study, so probably situation has changed a lot in a better way, but writing efficient code will always be a requirement.

[-] sim642@lemm.ee 1 points 1 year ago

That allows processes to be reused but the interpreter must still be set up cleanly each time and torn down. That includes things like open files, database connections and application configurations.

[-] kovalensky@lemmygrad.ml 1 points 1 year ago* (last edited 1 year ago)

Yes, you are completely right, if your code writing style is basic, all of it being solved by your application design. Not sure for open files (in contrast with disk cache of most OS), we have configurable persistent db connections, app configurations in most cases being saved in some cache (PHPBB cache is an example). Most of the time the code you wrote is the main factor of your code speed and waste coefficient. Luckily every year we get more modern PHP interpreter, if we look back at PHP 5, it was a complete disaster in the terms of performance, but I don't say that it will be as resource-saving as compiled languages ever (there always will be some cold-start overhead), it's pretty neat programming language, although I now consider lazy PHP developers as planet's nature-killers now :D

this post was submitted on 28 Oct 2023
107 points (95.7% liked)

Programmer Humor

32558 readers
565 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS