D
D
Dmitry Kuznetsov2021-12-06 11:23:35
PHP
Dmitry Kuznetsov, 2021-12-06 11:23:35

Is it possible to somehow optimize json_decode?

Good afternoon!
There is data coming from the database in the format:
- id
- payload (json)
After receiving the data and some conditions, I start a foreach loop, where each payload element is processed through json_decode. The problem is that json_decode runs about 90% of the entire request time, which is a very bottleneck of the algorithm. Those. the execution of the entire algorithm (request) takes, for example, 20 seconds, and the processing of json_decode takes 18 seconds. What is not good.

The question is actually the following: is it possible to speed up this json_decode somehow?

PS: Using a cache (redis, etc.) is not possible due to limited server resources and a large amount of data (although constantly changing).

UPD :
To understand the algorithm, I will quickly describe it:
From a variety of documents (ERP system), certain data with nestings are collected into one table and all this is written in json, so that it would be convenient to work with it further. In the report (where all this should be displayed) - we get all this data and display it with certain conditions (filters).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2021-12-06
@dima9595

No, you can't "optimize json_decode".
But to get rid of the idiotic algorithm, which, in order to get one record, decodes them all in turn, is possible and necessary.
And no childish babble about "oh, it's impossible to parse in advance, the site is spinning on my mother's iron" is not a hindrance here.
Parse, put in the database, when changing data, change them in the database, search in a human way, through SQL.
And the radish here didn’t rest on any side at all.

D
Dmitry Gordinskiy, 2021-12-06
@DmitriyGordinskiy

Change the base schema.
You can try using the halaxa/json-machine json parsing lib . It will help you make sure that the problem is not in parsing, but in the structure of the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question