cycle / database

Database Abstraction Layer, Schema Introspection, Schema Generation, Query Builders
MIT License
54 stars 22 forks source link

🐛 Interpolator optimization #68

Closed kafkiansky closed 1 year ago

kafkiansky commented 2 years ago

No duplicates 🥲.

Database

No matter.

What happened?

I insert 1000-5000 line batches and the default php.ini settings with memory_limit: 256M, then I periodically get allowed memory size of bytes exhausted. Worst of all, this error happens after the insertion, which is why my application can not correctly count the number of inserted batches. The error occurs on this line: https://github.com/cycle/database/blob/bd48dec079d7666dd125e1299be031b123685684/src/Driver/Driver.php#L462 I hope this helps.

Version

database 2.0
PHP 8.1
wolfy-j commented 2 years ago

I think we have to turn off interpolation of values not only for this reason.

hustlahusky commented 1 year ago

Recently I've found out that interpolator affects performance on big queries with many parameters.

My project have higher memory limit, so instead of getting allowed memory size of bytes exhausted I had long response times. I noticed that actual query execution takes like ~2s and its interpolation ~6s, which is quite a lot for simple parameters substitution.

I also stuck with own fork of cycle 1.x, so I fixed this issue for myself using preg_replace https://github.com/hustlahusky/cycle-database/commit/acb08be5ac2f49952b99790266c72b2f912b74b8

Interpolator haven't changed much since 1.x, so I'm pretty sure simple preg_replace would help