Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ztratar opened this issue Dec 22, 2023 · 4 comments
Labels

Comments

@ztratar
Copy link

ztratar commented Dec 22, 2023

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
Copy link
Contributor

bigmontz commented Jan 2, 2024

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

@bigmontz
Copy link
Contributor

bigmontz commented Jan 2, 2024

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
Copy link
Author

ztratar commented Jan 12, 2024

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants