sidorares / sidorares/node-mysql2
(QUESTION) Avoidance of anonymous function creation on each Connection.write invocation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
We create a new anonymous function for each write operation on Connection (which can be called up to 2 times, when we send header and body for large packets separately), while all it's doing is passing stream error to connection._handleNetworkError.
Could we benefit from lazily binding _handleNetworkError to connection instance (AFAIK, .bind() got significantly faster, at least in recent versions of Node) and alway passing the same bound function on .write() invocations?
I am just guessing here, so may be any benefits are negligible. But if it worth at least researching, I would gladly do it, if it wasn't done earlier.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading lib/connection.js around line 248 and trace how Connection.write passes stream errors to _handleNetworkError. Compare the current callback allocation with lazy binding, then benchmark writes including large packets split into header and body. Done means preserving error behavior while showing a meaningful performance benefit or documenting that the benefit is negligible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- databases
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100