T
T
Terion2012-09-08 14:16:30
PHP
Terion, 2012-09-08 14:16:30

What is the overhead in PHP on small objects?

I'm writing an ORM. I want it to suit myself and, most importantly, to be very fast (this is the main point - with the functionality I need and optimized as much as possible).
And now the question arose: when parsing objects, you need to select fields of certain types for properties, manipulate them, respectively.
It is more convenient, of course, to create a class for each type of field and instantiate it if necessary. But something bothers me. Isn't that too much overhead? There are many such small objects that can be created in one script.
I tried to find some information on this subject on the net - I did not find it.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
EugeneOZ, 2012-09-08
@Terion

You are dabbling in complete nonsense. If you need objects, then you need to make objects, you can't replace them with anything.
Make the architecture flexible first. Caching a single database query can save tens of thousands of times more time than saving on objects at the cost of architecture.

E
egorinsk, 2012-09-08
@egorinsk

Firstly, only tests will give an accurate answer. Sketch out a quick semblance of what you want to do and check how long it will take, for example, to create 100,000 objects.
Secondly, according to my observations, the problem is not so much in the time of creating objects, but in function calls, they are not very fast in PHP. When an object is created, at least the constructor is called, and the creation of 20 properties will result in a call to 20 functions.
I'd rather do without it. I think you are making life difficult for yourself.
In general, it is better to implement complex object constructions in languages ​​like .NET / Java, and not in scripting ones - everything will work much faster there.

A
Alexey Sundukov, 2012-09-08
@alekciy

There are no large or small objects in PHP by definition. Due to the untypified language. And the memory overhead can be estimated by looking at the structure of zend structures.
I found a translation about arrays on Habré: " How big are arrays (and values) in PHP? ", but there were definitely other articles that described the principle of organizing memory for PHP types very well.

V
Vladimir Chernyshev, 2012-09-08
@VolCh

It is more convenient, of course, to create a class for each type of field and instantiate it if necessary.
It is more convenient, IMHO, to simply cast SQL types to PHP types and back directly when reading / writing, unless you only use OOP wrappers for all scalar types in PHP in your application, such asif ($user->login.equal(new String($_POT['login']))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question