Comments (6)
Small demo of the problem: https://gist.github.com/cakoose/5271c469142205d37c600000cc22bb3e
from mammoth.
Mammoth automatically executes your query when you await it. This is done by adding a .then()
so the whole query looks like a promise and thus can be await'ed.
There isn't a function which we can change to async to make sure native async / await is triggered. How do you think we can fix this?
- Create an
async exec() { .. }
on every function — assuming this will trigger native async / await (is this true?). (a) This would be in addition to.then()
(b) remove.then()
so you must always explicitly.exec()
your queries. - Create some sort of trace capture mechanism similar to something like this one https://knexjs.org/#Installation-asyncStackTraces
- Anything else?
from mammoth.
Re 1: Using an explicit .exec()
appears to yield good stack traces: snippet. I would love to get it working for the plain .then
as well, but I don't know if it's possible. (I tried asking on the v8-users mailing list but never got a response.)
Re 2: That style of stack trace preservation isn't as efficient, and thus is not recommended in production. Having something only work in dev is still definitely useful, but I'm hoping we can get V8 native async stack traces working, which will work in both.
Tangent: Is an explicit .exec()
function a good idea?
Zapatos has an explicit .run(conn)
. Knex seems to do what Mammoth does. I don't know which is better but here are some thoughts:
When I first started using Mammoth, I preferred the idea of Zapatos' explicit .run(conn)
, since it separated the concerns of building the query and executing the query. But after having used Mammoth for a while, I've gotten used to the convenience of just doing await
😅 .
There's also a small practical advantage to Mammoth's approach: I can use the ESLint no-floating-promises rule to detect when I forget to await
. In theory, we should be able to write an ESLint rule to detect cases where someone builds a query but forgets to run it, but nobody has written that yet.
from mammoth.
Re 2: That style of stack trace preservation isn't as efficient, and thus is not recommended in production.
I do not see any performance differences in the happy path when enabling asyncStackTraces
in Knex (there is a simple benchmark in the repo now). Are you referring to the extra memory to keep track of the stack?
from mammoth.
I do not see any performance differences in the happy path when enabling
asyncStackTraces
in Knex (there is a simple benchmark in the repo now). Are you referring to the extra memory to keep track of the stack?
I was just going off of the warning in Knex's docs ("This has small performance overhead, so it is advised to use only for development.") and the general warnings around "async stack trace" libraries in general, e.g. longjohn
.
I assume the cost is mainly in generating the stack trace, but it probably adds some GC pressure too But maybe that overhead is not actually that much in this context because a remote DB query is already relatively expensive?
Where's the benchmark? I wonder if it's measuring a case where generating the stack is cheap for whatever reason, e.g. shallow stack.
from mammoth.
The benchmark is here https://github.com/Ff00ff/mammoth/tree/master/workspaces/sql-benchmarks. You are right, the stack isn't too deep so maybe that's why there is no significant overhead.
from mammoth.
Related Issues (20)
- ON CONSTRAINT name cannot be a parameter token HOT 1
- select where not like HOT 3
- Next package publication? HOT 5
- Support empty strings for DEFAULT HOT 2
- How to declare `IDENTITY` columns? HOT 2
- orderBy alias HOT 7
- Alias coalesce column HOT 4
- Automatically resolving schema and relationships directly from the database HOT 2
- Temporal tables
- Mixing `raw` with `Expression` values.
- `Array<Token>` is assignable to `Token`
- Way to associate additional metadata with schema?
- Support custom types
- Generated SQL for WHERE clause doesn't match AST nesting HOT 1
- How can we help Mammoth 2.x move forward?
- guidance for Date objects
- How to configure db.count() to return a `number` type?
- Query inside jsonb
- CASE statements don't include the `CASE` and `END` keywords
- Option for `.as()` output to be wrapped in double-quotes? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mammoth.