Code Monkey home page Code Monkey logo

node-swc's People

Contributors

adroitwhiz avatar anurbol avatar kdy1 avatar ricardobeat avatar simnalamburt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-swc's Issues

v1.1.43 Release

I see that 1.1.43 has been built as a release but is not available on NPM yet. Is there a timeline that it will be available?

transformSync with an AST does not transform

The following seems to only re-print the AST rather than actually transform. Passing the code directly works fine, but in cases where I need to do something with the AST prior to transforming, it would be nice to avoid reparsing.

swc.transformSync(swc.parseSync(code), {module: {type: 'commonjs'}})

Should this call process_js instead of print_js?

Error on alpine: Missing linux_musl-x64-83.node

On Alpine, I'm not sure if it's supposed to be possible to install swc, but I get the following failure

remote: #21 13.97 Command: node scripts/install.js || (npm install neon-cli && neon build --release)
remote: #21 13.97 Arguments:
remote: #21 13.97 Directory: /opt/app/node_modules/@swc/core
remote: #21 13.97 Output:
remote: #21 13.97 Thank you for using swc ( https://github.com/swc-project/swc ): super-fast javascript and typescript compiler
remote: #21 13.97
remote: #21 13.97 The project needs your help! Please consider supporting swc on Open Collective:
remote: #21 13.97 > https://opencollective.com/swc
remote: #21 13.97
remote: #21 13.97 Downloading binary from https://github.com/swc-project/node-swc/releases/download/v1.2.1/linux_musl-x64-83.node
remote: #21 13.97 Cannot download "https://github.com/swc-project/node-swc/releases/download/v1.2.1/linux_musl-x64-83.node":
remote: #21 13.97
remote: #21 13.97 HTTP error
remote: #21 13.97
remote: #21 13.97 Hint: If github.com is not accessible in your location
remote: #21 13.97       try setting a proxy via HTTP_PROXY, e.g.
remote: #21 13.97
remote: #21 13.97       export HTTP_PROXY=http://example.com:1234
remote: #21 13.97
remote: #21 13.97 or configure npm proxy via
remote: #21 13.97
remote: #21 13.97       npm config set proxy http://example.com:8080
remote: #21 13.97 npm notice created a lockfile as package-lock.json. You should commit this file.
remote: #21 13.97 + [email protected]
remote: #21 13.97 added 85 packages from 84 contributors and audited 85 packages in 3.035s
remote: #21 13.97
remote: #21 13.97 1 package is looking for funding
remote: #21 13.97   run `npm fund` for details
remote: #21 13.97
remote: #21 13.97 found 0 vulnerabilities
remote: #21 13.97
remote: #21 13.97 neon ERR! spawn cargo ENOENT
remote: #21 13.97
remote: #21 13.97 Error: spawn cargo ENOENT
remote: #21 13.97     at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
remote: #21 13.97     at onErrorNT (internal/child_process.js:468:16)
remote: #21 13.97     at processTicksAndRejections (internal/process/task_queues.js:84:21)
remote: #21 13.97 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
remote: #21 ERROR: executor failed running [/bin/sh -c yarn]: runc did not terminate sucessfully

the install script is looking for a linux_musl-x64-83.node target, but it's not available in the release folder.

Maybe there is something special to do to install on alpine?
Maybe it's not possible at all?

node14.2.0

Downloading binary from https://npm.taobao.org/mirrors/node-swc/v1.1.42/darwin-x64-83.node
Cannot download "https://npm.taobao.org/mirrors/node-swc/v1.1.42/darwin-x64-83.node":

node14.2.0

~ node
Welcome to Node.js v14.2.0.
Type ".help" for more information.
> process.versions.modules
'83'
> process.versions
{
  node: '14.2.0',
  v8: '8.1.307.31-node.33',
  uv: '1.37.0',
  zlib: '1.2.11',
  brotli: '1.0.7',
  ares: '1.16.0',
  modules: '83',
  nghttp2: '1.40.0',
  napi: '6',
  llhttp: '2.0.4',
  openssl: '1.1.1g',
  cldr: '36.1',
  icu: '66.1',
  tz: '2019c',
  unicode: '13.0'
}
>

Calling async API from node worker threads results in errors

Calling e.g. swc.parse from inside a node worker thread results in errors like the following:

FATAL ERROR: HandleScope::HandleScope Entering the V8 API without proper locking in place

This is likely due to calling the callback on the wrong thread, or with the wrong napi environment. I'm not familiar with Rust so I'm not sure where to debug further, but that's been my experience in C++.

Smaller binary size

On AMD64 Linux with Rust 1.42.0-nightly+6d3f4e0aa, the size of libffi.so is 25279568B = 26.23MiB, which is rather big. There're 2 options that we can do without tradeoffs, and 1 option that we can choose between tradeoff.

  1. Enable LTO: 26.23MiB → 24.11MiB, -8%

    I just found that LTO was disabled on purpose at commit ffde24e0. Was there any reason?

  2. Strip the binary: 26.23MiB → 20.89MiB, -20%

    simple strip -s libffi.so is enough.

  3. Use Trait Object and vtable instead of generic instantiation and monomorphism for a few big functions.

    We don't need to avoid monomorphism at all. Just disabling it for a few big functions will suffice. For example, single "swc_ecma_ast::expr::fold_children" takes 1.225MiB which is 5% of binary.

    Using Trait Object will introduce a small runtime overhead. We need to measure the amount of overhead so that we can choose wisely between tradeoffs.

See summary.gz for summary of cargo-bloat result.
See cargo-bloat.json.gz for full cargo-bloat result.

A code that I used to generate 'summary.gz'
#!/usr/bin/env python3
import json, collections
data = json.load(open('cargo-bloat.json'))
accum = collections.defaultdict(int)
for entry in data['functions']:
    accum[entry['name']] += entry['size']
for fn, size in sorted(accum.items(), key=lambda e:e[1], reverse=True):
    print(f'{size:10}\t{fn}')

`i686-pc-windows-msvc` target may not be installed

I don't really know if I am doing something very naive or not but I am trying to build node-swc
by running neon-cli build --release and I got this error.


Compiling ppv-lite86 v0.2.
Compiling rand_core v0.4.2
  error[E0463]: can't find crate for `std`
  |
  = note: the `i686-pc-windows-msvc` target may not be installed

Why does it tries to install something related to i686 when I am on 64 bit Windows 10?

Can't seem to install

With both node-v12.16.1-linux-x64 and node-v13.12.0-linux-x64 I can't seem to get npm install or yarn install to work.

I get the following errors:

npm WARN rm not removing /home/jonathan/debugging/node-swc/node_modules/.bin/semver as it wasn't installed by /home/jonathan/debugging/node-swc/node_modules/semver
npm WARN rm not removing /home/jonathan/debugging/node-swc/node_modules/.bin/json5 as it wasn't installed by /home/jonathan/debugging/node-swc/node_modules/json5
npm WARN rm not removing /home/jonathan/debugging/node-swc/node_modules/.bin/jsesc as it wasn't installed by /home/jonathan/debugging/node-swc/node_modules/jsesc

> [email protected] install /home/jonathan/debugging/node-swc/node_modules/microtime
> prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=13.12.0 runtime=node arch=x64 libc= platform=linux)
make: Entering directory '/home/jonathan/debugging/node-swc/node_modules/microtime/build'
  CXX(target) Release/obj.target/microtime/src/microtime.o
In file included from ../../nan/nan_converters.h:67:0,
                 from ../../nan/nan.h:222,
                 from ../src/microtime.cc:9:
../../nan/nan_converters_43_inl.h: In static member function ‘static Nan::imp::ToFactoryBase<v8::Boolean>::return_t Nan::imp::ToFactory<v8::Boolean>::convert(v8::Local<v8::Value>)’:
../../nan/nan_converters_43_inl.h:18:51: error: no matching function for call to ‘v8::Value::ToBoolean(v8::Local<v8::Context>)’
       val->To ## TYPE(isolate->GetCurrentContext())                            \
                                                   ^
../../nan/nan_converters_43_inl.h:22:1: note: in expansion of macro ‘X’
 X(Boolean)
 ^
In file included from /home/jonathan/.cache/node-gyp/13.12.0/include/node/node.h:67:0,
                 from ../../nan/nan.h:53,
                 from ../src/microtime.cc:9:
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:2762:18: note: candidate: v8::Local<v8::Boolean> v8::Value::ToBoolean(v8::Isolate*) const
   Local<Boolean> ToBoolean(Isolate* isolate) const;
                  ^~~~~~~~~
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:2762:18: note:   no known conversion for argument 1 from ‘v8::Local<v8::Context>’ to ‘v8::Isolate*’
In file included from ../../nan/nan_converters.h:67:0,
                 from ../../nan/nan.h:222,
                 from ../src/microtime.cc:9:
../../nan/nan_converters_43_inl.h: In static member function ‘static Nan::imp::ValueFactoryBase<bool>::return_t Nan::imp::ToFactory<bool>::convert(v8::Local<v8::Value>)’:
../../nan/nan_converters_43_inl.h:37:57: error: no matching function for call to ‘v8::Value::BooleanValue(v8::Local<v8::Context>)’
   return val->NAME ## Value(isolate->GetCurrentContext());                     \
                                                         ^
../../nan/nan_converters_43_inl.h:40:1: note: in expansion of macro ‘X’
 X(bool, Boolean)
 ^
In file included from /home/jonathan/.cache/node-gyp/13.12.0/include/node/node.h:67:0,
                 from ../../nan/nan.h:53,
                 from ../src/microtime.cc:9:
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:2771:8: note: candidate: bool v8::Value::BooleanValue(v8::Isolate*) const
   bool BooleanValue(Isolate* isolate) const;
        ^~~~~~~~~~~~
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:2771:8: note:   no known conversion for argument 1 from ‘v8::Local<v8::Context>’ to ‘v8::Isolate*’
In file included from ../../nan/nan_new.h:189:0,
                 from ../../nan/nan.h:223,
                 from ../src/microtime.cc:9:
../../nan/nan_implementation_12_inl.h: In static member function ‘static Nan::imp::FactoryBase<v8::StringObject>::return_t Nan::imp::Factory<v8::StringObject>::New(v8::Local<v8::String>)’:
../../nan/nan_implementation_12_inl.h:356:37: error: no matching function for call to ‘v8::StringObject::New(v8::Local<v8::String>&)’
   return v8::StringObject::New(value).As<v8::StringObject>();
                                     ^
In file included from /home/jonathan/.cache/node-gyp/13.12.0/include/node/node.h:67:0,
                 from ../../nan/nan.h:53,
                 from ../src/microtime.cc:9:
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:5688:23: note: candidate: static v8::Local<v8::Value> v8::StringObject::New(v8::Isolate*, v8::Local<v8::String>)
   static Local<Value> New(Isolate* isolate, Local<String> value);
                       ^~~
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:5688:23: note:   candidate expects 2 arguments, 1 provided
In file included from ../../nan/nan_new.h:189:0,
                 from ../../nan/nan.h:223,
                 from ../src/microtime.cc:9:
../../nan/nan_implementation_12_inl.h:356:58: error: expected primary-expression before ‘>’ token
   return v8::StringObject::New(value).As<v8::StringObject>();
                                                          ^
../../nan/nan_implementation_12_inl.h:356:60: error: expected primary-expression before ‘)’ token
   return v8::StringObject::New(value).As<v8::StringObject>();
                                                            ^
In file included from /usr/include/c++/7/cassert:44:0,
                 from /home/jonathan/.cache/node-gyp/13.12.0/include/node/node_object_wrap.h:26,
                 from ../../nan/nan.h:55,
                 from ../src/microtime.cc:9:
../../nan/nan_object_wrap.h: In destructor ‘virtual Nan::ObjectWrap::~ObjectWrap()’:
../../nan/nan_object_wrap.h:24:25: error: ‘class Nan::Persistent<v8::Object>’ has no member named ‘IsNearDeath’
     assert(persistent().IsNearDeath());
                         ^
../../nan/nan_object_wrap.h: In static member function ‘static void Nan::ObjectWrap::WeakCallback(const v8::WeakCallbackInfo<Nan::ObjectWrap>&)’:
../../nan/nan_object_wrap.h:127:26: error: ‘class Nan::Persistent<v8::Object>’ has no member named ‘IsNearDeath’
     assert(wrap->handle_.IsNearDeath());
                          ^
../src/microtime.cc: In function ‘void NowStruct(const Nan::FunctionCallbackInfo<v8::Value>&)’:
../src/microtime.cc:75:78: error: no matching function for call to ‘v8::Array::Set(Nan::imp::IntegerFactory<v8::Integer>::return_t, Nan::imp::FactoryBase<v8::Number>::return_t)’
   array->Set(Nan::New<v8::Integer>(0), Nan::New<v8::Number>((double)t.tv_sec));
                                                                              ^
In file included from /home/jonathan/.cache/node-gyp/13.12.0/include/node/node.h:67:0,
                 from ../../nan/nan.h:53,
                 from ../src/microtime.cc:9:
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:3547:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
                                     ^~~
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:3547:37: note:   candidate expects 3 arguments, 2 provided
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:3550:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
                                     ^~~
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:3550:37: note:   candidate expects 3 arguments, 2 provided
../src/microtime.cc:76:79: error: no matching function for call to ‘v8::Array::Set(Nan::imp::IntegerFactory<v8::Integer>::return_t, Nan::imp::FactoryBase<v8::Number>::return_t)’
   array->Set(Nan::New<v8::Integer>(1), Nan::New<v8::Number>((double)t.tv_usec));
                                                                               ^
In file included from /home/jonathan/.cache/node-gyp/13.12.0/include/node/node.h:67:0,
                 from ../../nan/nan.h:53,
                 from ../src/microtime.cc:9:
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:3547:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
                                     ^~~
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:3547:37: note:   candidate expects 3 arguments, 2 provided
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:3550:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
                                     ^~~
/home/jonathan/.cache/node-gyp/13.12.0/include/node/v8.h:3550:37: note:   candidate expects 3 arguments, 2 provided
microtime.target.mk:111: recipe for target 'Release/obj.target/microtime/src/microtime.o' failed
make: *** [Release/obj.target/microtime/src/microtime.o] Error 1
make: Leaving directory '/home/jonathan/debugging/node-swc/node_modules/microtime/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/jonathan/Software/node-v13.12.0-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Linux 5.3.0-42-generic
gyp ERR! command "/home/jonathan/Software/node-v13.12.0-linux-x64/bin/node" "/home/jonathan/Software/node-v13.12.0-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/jonathan/debugging/node-swc/node_modules/microtime
gyp ERR! node -v v13.12.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/jonathan/.npm/_logs/2020-04-05T12_34_19_283Z-debug.log

Removing bench-runner from the devDependencies fixes this issue.

However I get the following:

> @swc/[email protected] prepublish /home/jonathan/debugging/node-swc
> tsc -d

src/index.ts:13:16 - error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`.

13 const native = require("./native");
                  ~~~~~~~

src/index.ts:18:24 - error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`.

18 export const version = require("./package.json").version;
                          ~~~~~~~

src/util.ts:96:1 - error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`.

96 module.exports = {
   ~~~~~~


Found 3 errors.

Installing this dependency gets it installed.

Use serde_json with JSON.parse

neon_serde

[parse]
  parse x 895 ops/sec ±0.40% (88 runs sampled)
  parse + print x 106 ops/sec ±0.34% (74 runs sampled)

serde_json for print*

[parse]
  parse x 1,931 ops/sec ±0.86% (87 runs sampled)
  parse + print x 113 ops/sec ±0.35% (77 runs sampled)

serde_json for parse* and print*

[parse]
  parse x 1,955 ops/sec ±0.59% (88 runs sampled)
  parse + print x 418 ops/sec ±0.38% (86 runs sampled)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.