Skip to content

sqlite: add fast api to DatabaseSync.isTransaction #57952

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Apr 20, 2025

This might be a good start to add v8 fast api before we stabilize sqlite. I couldn't find the build error. Maybe @cjihrig might help?

For reproduction, run: make && tools/test.py test/parallel/test-sqlite-database-sync.js

#
# Fatal error in , line 0
# Check failed: v8_flags.fuzzing.
#
#
#
#FailureMessage Object: 0x16ba5da08
----- Native stack trace -----

 1: 0x1044fd394 node::NodePlatform::GetStackTracePrinter()::$_0::__invoke() [/Users/yagiz/coding/node/out/Release/node]
 2: 0x105b63c28 V8_Fatal(char const*, ...) [/Users/yagiz/coding/node/out/Release/node]
 3: 0x106288ab0 v8::internal::Runtime_OptimizeOsr(int, unsigned long*, v8::internal::Isolate*) (.cold.1) [/Users/yagiz/coding/node/out/Release/node]
 4: 0x104c5ced8 v8::internal::Runtime_OptimizeOsr(int, unsigned long*, v8::internal::Isolate*) [/Users/yagiz/coding/node/out/Release/node]
 5: 0x105258d08 Builtins_CEntry_Return1_ArgvInRegister_NoBuiltinExit [/Users/yagiz/coding/node/out/Release/node]
 6: 0x10533f9b4 Builtins_CallRuntimeHandler [/Users/yagiz/coding/node/out/Release/node]
 7: 0x1051bc9f8 Builtins_InterpreterEntryTrampoline [/Users/yagiz/coding/node/out/Release/node]     8: 0x1051bc9f8 Builtins_InterpreterEntryTrampoline [/Users/yagiz/coding/node/out/Release/node]     9: 0x1136e5638                                                                                    10: 0x1136f88c8                                                                                    11: 0x1136e96d8                                                                                    12: 0x1136f5afc
13: 0x1136f9bec
14: 0x1051fb8c8 Builtins_AsyncFunctionAwaitResolveClosure [/Users/yagiz/coding/node/out/Release/node]                                                                                                 15: 0x1052ce0d8 Builtins_PromiseFulfillReactionJob [/Users/yagiz/coding/node/out/Release/node]
16: 0x1051eacd0 Builtins_RunMicrotasks [/Users/yagiz/coding/node/out/Release/node]                 17: 0x1051ba550 Builtins_JSRunMicrotasksEntry [/Users/yagiz/coding/node/out/Release/node]          18: 0x10478ccb0 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/yagiz/coding/node/out/Release/node]
19: 0x10478d574 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/yagiz/coding/node/out/Release/node] 20: 0x10478d694 v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*) [/Users/yagiz/coding/node/out/Release/node]
21: 0x106264148 v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [/Users/yagiz/coding/node/out/Release/node]
22: 0x106264438 v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) (.cold.1) [/Users/yagiz/coding/node/out/Release/node]
23: 0x1047b9e08 v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) [/Users/yagiz/coding/node/out/Release/node]
24: 0x1051beb38 Builtins_CallApiCallbackGeneric [/Users/yagiz/coding/node/out/Release/node]        25: 0x1051bc9f8 Builtins_InterpreterEntryTrampoline [/Users/yagiz/coding/node/out/Release/node]
26: 0x1051ba66c Builtins_JSEntryTrampoline [/Users/yagiz/coding/node/out/Release/node]             27: 0x1051ba310 Builtins_JSEntry [/Users/yagiz/coding/node/out/Release/node]                       28: 0x10478ccf0 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/yagiz/coding/node/out/Release/node]             29: 0x10478c680 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) [/Users/yagiz/coding/node/out/Release/node]                                              30: 0x104638bac v8::Function::Call(v8::Isolate*, v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/Users/yagiz/coding/node/out/Release/node]                                31: 0x1043c5e78 node::InternalCallbackScope::Close() [/Users/yagiz/coding/node/out/Release/node]
32: 0x1043c588c node::InternalCallbackScope::~InternalCallbackScope() [/Users/yagiz/coding/node/out/Release/node]                                                                                     33: 0x10445ba88 node::StartExecution(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) [/Users/yagiz/coding/node/out/Release/node]
34: 0x1043ca828 node::LoadEnvironment(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>, std::__1::function<void (node::Environment*, v8::Local<v8::Value>, v8::Local<v8::Value>)>) [/Users/yagiz/coding/node/out/Release/node]                35: 0x1044c9c28 node::NodeMainInstance::Run() [/Users/yagiz/coding/node/out/Release/node]          36: 0x10445f7ac node::Start(int, char**) [/Users/yagiz/coding/node/out/Release/node]
37: 0x18fdec274 start [/usr/lib/dyld]                                                              Command: out/Release/node --expose-internals --allow-natives-syntax --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/yagiz/coding/node/test/parallel/test-sqlite-database-sync.js
--- CRASHED (Signal: 5) ---

                                                                                                   [00:00|% 100|+   0|-   1]: Done
Failed tests:
out/Release/node --expose-internals --allow-natives-syntax --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/yagiz/coding/node/test/parallel/test-sqlite-database-sync.js

@anonrig anonrig requested review from jasnell, targos and cjihrig April 20, 2025 16:29
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Apr 20, 2025
Copy link

codecov bot commented Apr 20, 2025

Codecov Report

Attention: Patch coverage is 68.42105% with 6 lines in your changes missing coverage. Please review.

Project coverage is 90.27%. Comparing base (4cd8e19) to head (5a9ad71).

Files with missing lines Patch % Lines
src/node_sqlite.cc 68.42% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57952      +/-   ##
==========================================
- Coverage   90.27%   90.27%   -0.01%     
==========================================
  Files         630      630              
  Lines      186328   186343      +15     
  Branches    36503    36503              
==========================================
+ Hits       168205   168217      +12     
- Misses      11001    11009       +8     
+ Partials     7122     7117       -5     
Files with missing lines Coverage Δ
src/node_sqlite.h 68.00% <ø> (ø)
src/node_sqlite.cc 80.38% <68.42%> (-0.18%) ⬇️

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cjihrig
Copy link
Contributor

cjihrig commented Apr 21, 2025

The crash happens in the test on this line:

eval('%PrepareFunctionForOptimization(db.isTransaction)');

Changing the line to DatabaseSync.prototype.isTransaction does not work either. Do we know if getters are supported by the fast API?

@anonrig
Copy link
Member Author

anonrig commented Apr 21, 2025

Do we know if getters are supported by the fast API?

@joyeecheung @jasnell maybe you know?

@jasnell
Copy link
Member

jasnell commented Apr 23, 2025

I do not know, sorry.

Copy link
Member

@H4ad H4ad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can try expose it via getter on https://github.com/nodejs/node/blob/02849f83978debf8fb66453bfbae0ab7ae2cb07a/lib/sqlite.js, and then add the fastAPI in a method exposed by the sqlite binding.

@anonrig anonrig force-pushed the yagiz/add-fast-api-to-sqlite branch from 02849f8 to 889a597 Compare April 25, 2025 14:14
@anonrig
Copy link
Member Author

anonrig commented Apr 25, 2025

Maybe you can try expose it via getter on https://github.com/nodejs/node/blob/02849f83978debf8fb66453bfbae0ab7ae2cb07a/lib/sqlite.js, and then add the fastAPI in a method exposed by the sqlite binding.

@cjihrig @H4ad With the help of @erikcorry we found the issue, it seems the issue is with optimizing functions through OptimizeFunctionOnNextCall. We can not optimize a C++ function, we have to surround it with a JavaScript function first.

@anonrig anonrig requested a review from H4ad April 25, 2025 14:15
@anonrig anonrig force-pushed the yagiz/add-fast-api-to-sqlite branch from 889a597 to cbce897 Compare April 25, 2025 14:21
@cjihrig
Copy link
Contributor

cjihrig commented Apr 25, 2025

Interesting. That seems like something worth documenting in https://github.com/nodejs/node/blob/main/doc/contributing/adding-v8-fast-api.md.

@anonrig
Copy link
Member Author

anonrig commented Apr 25, 2025

Interesting. That seems like something worth documenting in https://github.com/nodejs/node/blob/main/doc/contributing/adding-v8-fast-api.md.

I'll open a PR but first I need to wait for a response at the v8-dev - https://groups.google.com/g/v8-dev/c/Mr-1Dx7clBY

Copy link
Member

@H4ad H4ad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: Do we have benchmarks for sqlite (at least I didn't found)? I don't doubt this will help, but would be great to have something to compare and see the improvements

@anonrig
Copy link
Member Author

anonrig commented Apr 26, 2025

Side note: Do we have benchmarks for sqlite (at least I didn't found)? I don't doubt this will help, but would be great to have something to compare and see the improvements

I don't think there is, but we should definitely have. It seems the tests are not passing because fast path counter isn't increased. I wonder if the fast path isn't invoked because we're testing it on debug builds? Can it be possible @targos @joyeecheung?

@anonrig anonrig force-pushed the yagiz/add-fast-api-to-sqlite branch 4 times, most recently from dbf13de to 80f5503 Compare April 26, 2025 17:32
@anonrig anonrig force-pushed the yagiz/add-fast-api-to-sqlite branch from 80f5503 to 5a9ad71 Compare April 26, 2025 17:32
@H4ad
Copy link
Member

H4ad commented Apr 26, 2025

I don't think there is, but we should definitely have.

I will open a PR to add some benchmarks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants