Hello!
Somebody of you may know that current wrappers (ghmattimysql/fivem-mysql-async) uses node-mysql which has some issue with MySQL 8`s authentication as mentioned in this issue
Recommended node-mysql2 offers better performance and new features listed in readme at it´s repo. Therefore I attempt to make completely new middleware wrapper using it.
Source code can be found here.
After some testing [commit] we get more performance, about 3-times but strange bug came in. If the export was called after any Wait() or more generally inside coroutine then query/callback times was very very random (1ms, 15ms, 50ms, 100ms). Old wrappers could not reproduce this (always about 50ms). So i thought it was something with thread affinity.
After implementing setImmediate() inside callbacks [commit] performance gets even worse! (100+ ms).
So I was searching everywhere on discord, forum and found some discussion about implementing mongodb wrapper and about process.nextTick().
Without any hard core studying I removed setImmediate() and add process.nextTick() at the end of every export. [commit - read description]
Finally achieved some improvement.

Measured using os.clock() - node-mysql2
node-mysql2 first query/prepared query/after Wait vs ghmattimysql

Measured using os.clock() - ghmattimysql
So i would like to ask few questions:
-
Why
process.nextTick()improved performance a lot? and how? -
Is it good practice to invoke it at the end of export?
-
Why there is random query times if we invoke bare callback? Without
setImmediate()orprocess.nextTick()
I hope you understand what I am talking about.
Thank you for your time spent reading this
and looking forward to your answers!
