Repository navigation
Stream Parser using Generators - #285
Conversation
|
I still need to figure out how to chain this all together (e.g. for running the unit tests). |
|
By the way, I also executed the benchmarks against So with this PR, tedious will be both faster and use less memory when handling binary data than the official, binary Microsoft TDS driver for Node. 😆 |
f8f7c33 to
0bda03f
Compare
|
I'm not quite sure why the build is passing on Travis, as everything should be failing right now. |
|
I love the idea of using generators. It also gives the opportunity to completely revamp the Tedious API, which is, as the name implies, rather tedious to use. I always thought the API should look something like what I did with Tedium. It may be time to start thinking about what Tedious 2.0 looks like. Having a transpiled ES5 version is fine, but generators are the way of the future, and pushing people in that direction is the right way to go. I would prefer to see the reverse situation from now, where the generators version is the base library, and if you need an old-style library, that can be provided via a wrapper library. Unfortunately I'm no longer actively using Tedious, and my time for contributing is practically non-existent, but I'm always happy to give feedback. |
|
@bretcope well, the change here is rather basic and is limited to the internals of Tedious. Regarding "the future": I think generators are only a stopgap solution, "async/await" using Promises is the way to go. But that should not block us from using generators right now to improve. 😃 EDIT: And yes, I now, |
0bda03f to
a1824ff
Compare
|
I agree that they're a stopgap, but transitioning from generators to async/await is pretty straight forward compared to transitioning from callbacks. Basically replacing I haven't seen any implementation of async/await yet, so it's hard to know how far off those are. I think if there were a desire to redo the api (much needed, in my opinion), then generators would be the way to go for now. I'm also _HUGELY_ in favor of ditching coffeescript. I've always found it frustrating, difficult to read, and I think it limits the number of people interested in contributing. But, like I said, I'm not particularly active in writing code for Tedious anymore, so I don't have much stake in the decision. |
|
The build is passing now (on both Travis as well as Appveyor). @patriksimek @bretcope @pekim I'd like to go ahead and merge this, and then maybe start iterating towards moving Tedious off of CoffeeScript and onto idiomatic "ES6/ES7/ES2015/ESnext/whatever else it's called today" using babel. The source will still need transpilation to be able to execute on older versions of iojs and Node.js, but it will be "plain" JavaScript. 😄 I'll also continue working on moving the tests to mocha (I really can't take this nodeunit nonsense anymore). I'll try to do this conversion in steps, which means we'll have both ES* code and CoffeeScript code living together until the migration is done. If you got any concerns, please let me know, Feedback is very welcome. |
|
I know I don't do much on this these days, but I'm definitely 👍 for bringing tedious into the modern JS age |
|
It all sounds good to me. My biggest regret with tedious was using coffeescript. And I never did like the backtracking of packet token parsing. Great job Arthur. |
|
@pekim Thanks. Okay, so here's my plan for now.
Everything will be done step-by-step, and after each major milestone, I want to release a new tedious version, on a regular basis. I don't want to end in a situation where development on the old code base becomes stale because a "rewrite" is in the works. Thanks everyone. |
|
Great work @arthurschreiber! |
|
I just ran this against |
|
Okay, I finally got releases via Travis working. Apparently, you can't release to npm using npm 1.x, but the node 0.10 build job on travis still uses that npm version. Changing our builds to always update to the latest npm fixed that issue. Sorry for the resulting noise. I'll go ahead and merge this and release it as |
Stream Parser using Generators
TL;DR
Make Tedious fast and use less memory using the magic of generators.
Stream Parser using Generators
This is an alternative to #225.
Instead of using the
dissolvemodule to do the parsing, I'm using ES2015 Generators instead. This makes the code a lot more readable and the necessary changes to convert the existing code to stream parser a lot less intrusive (check the diff to see how "simple" the actual changes are).As ES2015 Generators are only available by default with io.js, I'm using babel as an additional transpilation step to convert the generators to ES5 compatible code.
This introduces a few new runtime dependencies (
babel-runtime,blandreadable-stream) and a new development dependency (babel).Benchmarks:
Transpiled generators are generally fast. Here's a benchmark from running the code that is generated by compiling the coffeescript code into JS and transpiling that using babel:
This is faster than the change that I proposed in #225, while being less intrusive and a lot easier to maintain in the long term.
Regarding the inclusion of
babel: I'd love to convert Tedious from CoffeeScript to ES2015. CoffeeScript was a welcome improvement over plain old javascript, but nowadays we have ES2015 giving us most of the sugar that CoffeeScript provided while being natively supported by io.js (and it's easily transpiled usingbabelfor older Node.JS versions).This is something that we maintainers probably need to discuss seperately from this issue.
Any thoughts?