neo4j / neo4j-javascript-driver

Neo4j Bolt driver for JavaScript
https://neo4j.com/docs/javascript-manual/current/
Apache License 2.0
839 stars 148 forks source link

Enabling node.js source maps increases neo4j-driver total execution time by 70x+ on my machine #1168

Open ztratar opened 6 months ago

ztratar commented 6 months ago

When i run neo4j in my node.js app, if --enable-source-maps is enabled, the average query time moves from 10ms to over a second.

Some more details:

We have a node.js backend application. When I run in using yarn dev (e.g. DEBUG=backend* node --enable-source-maps build.js --start --watch")

All queries and operations take about a second minimum.

image

When I then build that javascript app "rm -rf dist && NODE_ENV=development node build.js And then run dist/index.js.. boom, 1 second turns to 7ms.

image

For building I am using esbuild. When I run a hybrid node build.js --start --watch manually... even though I'm watching as in normal dev mode, the query time remains performant.

I've been able to narrow this down to purely source maps. I don't know why source maps should affect neo4j query performance, but I would like to have them enabled and still be able to run development with speedy queries.

bigmontz commented 6 months ago

Thanks for the report @ztratar, which driver and node versions are you using?

bigmontz commented 6 months ago

I don't have issue with my simple esbuild setup here:

package.json

{
  "name": "gh1168",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "esbuild": "^0.19.11"
  },
  "dependencies": {
    "neo4j-driver": "^5.16.0"
  },
  "scripts": {
    "build": "esbuild index.js --bundle --platform=node --sourcemap --outfile=bin/out.js"
  }
}

index.js

const neo4j = require('neo4j-driver')

const driver = neo4j.driver('neo4j://localhost:7687', neo4j.auth.basic('neo4j', 'password'))

performance.measure('Start to Now');
performance.mark('Before Query');

driver.executeQuery('RETURN 1', {}, {
    database: 'neo4j'
}).then(() => {
    performance.mark('After Query')

    const measure = performance.measure('Query Time', 'Before Query', 'After Query');

    console.log('Query took', measure.duration)
}).finally(() => driver.close())

Command line:

yarn build && node bin/out.js
ztratar commented 5 months ago

Hello! This was happening on 16.19.

We've now upgraded to node 20 LTS, and, oddly enough, it appears the query times have all improved to normal with that change.

bigmontz commented 5 months ago

I've tried my sample with project with node v16.19.0 and I can't reproduce the problem. I can't figure out what's happening. Can you reproduce the problem with the setup I shared?

Thanks