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

Why are "install script" times 20 seconds? #1043

Closed
timothymiller opened this issue Aug 15, 2023 · 12 comments
Closed

Why are "install script" times 20 seconds? #1043

timothymiller opened this issue Aug 15, 2023 · 12 comments

Comments

@timothymiller
Copy link

Thank you for your hard work creating a wonderful library for sqlite.

Background

I am running better-sqlite3 in a turborepo with Cloudflare D1. My pnpm install times are 22 seconds, even with turborepo cache enabled.

Most of the total time is spent on this step:

node_modules/better-sqlite3: Running install script, done in 20.6s

How to reproduce

My reproduction repo is here.

Call to action

What is happening in this install script? Can it be cached? Any recommendations are much appreciated!

@timothymiller timothymiller changed the title Slow install script [question] Install script times are 20+ seconds Aug 15, 2023
@coniferconcepts
Copy link

Seeing this as well. Thanks!

@timothymiller timothymiller changed the title [question] Install script times are 20+ seconds [bug] Why are "install script" times 20 seconds? Aug 16, 2023
@ItsWendell
Copy link

ItsWendell commented Aug 16, 2023

../../node_modules/better-sqlite3: Running install script, done in 2m 23.1s
../../node_modules/es5-ext: Running postinstall script, done in 195ms
../../node_modules/esbuild: Running postinstall script, done in 176ms
../../node_modules/protobufjs: Running postinstall script, done in 161ms
../../node_modules/turbo: Running postinstall script, done in 331ms
../../node_modules/workerd: Running postinstall script, done in 203ms
../../node_modules/yarn: Running preinstall script, done in 158ms
## Custom post install output here removed (4 seconds)
Done in 2m 59.6s

I'm seeing super slow times locally too, luckily we don't have this bad of times on our CI.

@neoxpert
Copy link
Contributor

I don't have slow install times for better-sqlite3 in my projects. Which NodeJS / Electron version are you using / targetting, have you checked if there is a recompile happening?

@timothymiller
Copy link
Author

I don't have slow install times for better-sqlite3 in my projects. Which NodeJS / Electron version are you using / targetting, have you checked if there is a recompile happening?

I'm targeting Node.js v18 (latest LTS) in local dev. The lib is being used in a cloudflare workers environment for communicating with D1.

How could I check if there is a recompile happening?

@timothymiller
Copy link
Author

I'm seeing high single CPU usage during the better-sqlite3 install script stage. Seems like it is recompiling?

Certainly this lib supports mac-arm64?

@neoxpert
Copy link
Contributor

It is supported, yes. Otherwise the compilation would fail anyway. But right now there is no prebuilt binary for the use in NodeJS on arm64, only for Electron. There is still an open pull request #1002 that would add those prebuilt binaries.

A pragmatic way to see if the module has been recompiled, without fiddling with logs and flasgs etc. would be to have a look at node_modules/better-sqlite3/build/Release after the module has been installed. If there is any other file than better_sqlite3.node, the module has been recompiled.

@JoshuaWise JoshuaWise changed the title [bug] Why are "install script" times 20 seconds? Why are "install script" times 20 seconds? Aug 28, 2023
@timothymiller
Copy link
Author

The issue seems to have been re-introduced in 8.5.1 & 8.5.2.
I'm seeing recompiles happen on 8.5.2 on macOS arm64

@neoxpert
Copy link
Contributor

As you are using pnpm, do you have node-gyp installed for it (pnpm install -g node-gyp)? Might be the same issue as in #1027.

@timothymiller
Copy link
Author

I do have node-gyp installed

@enfipy
Copy link

enfipy commented Sep 26, 2023

Also suffering from this issue (persists in 8.6.0). The only package that takes 30+ seconds to recompile every pnpm i on my M1 mac.

I'm using Nx (same with Turbo), with Cloudflare D1 and DrizzleORM. I will be more than glad to provide more information if needed to fix this issue.

P.S: node-gyp@9.4.0 is installed globally.

UPDATE: Issue persists in better-sqlite3@v9.0.0.

@neoxpert
Copy link
Contributor

When better-sqlite3 get's recompiled everytime you are either using a runtime where no prebuilt binary is available or something in the toolchain (pnpm, prebuild-install .. ) resolves the wrong architecture / url of the prebuilt binary to load. I don't think that the overall problem is to be solved by better-sqlite3 itself but within the tools used to provide, dsitribute and resolve the prebuilt binaries.

Does the issue also occur using npm instead of pnpm? Does it also happen when installing this minimal project?

{
  "name": "testing",
  "version": "1.0.0",
  "engines" : { 
    "node": ">=18.0.0"
  },
  "dependencies": {
    "better-sqlite3": "9.1.1"
  }
}

@mceachen
Copy link
Member

mceachen commented Apr 7, 2024

Closing due to inactivity

@mceachen mceachen closed this as completed Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

7 participants