Giter Club home page Giter Club logo

quickjs's Introduction

QuickJS

A community-driven QuickJS fork.

Optimizations

In addition to the relevant features and optimizations in the TODO file, the more important optimizations are:

  • Column number
  • Basic Debugger API
  • Poly IC
    • Self Poly IC
    • Prototype Poly IC
  • Replace malloc To mimalloc
  • Improve The Performance Of GC

In our plan, we first complete the above optimizations and then gradually add the remaining parts.

Develop

Clone

git clone --recurse-submodules https://github.com/openquickjs/quickjs.git

Install Build Tools

brew install cmake ninja # macOS
sudo apt install cmake ninja-build # Ubuntu

The Windows build environment is not yet officially supported.

Build

bash scripts/build.sh # build quickjs qjs
bash scripts/test.sh # run test262 tests

You can find libquickjs.a in lib folder and qjs / run-test262 in bin folder.

  1. If you're using Visual Studio Code, you can use the CMake Tools extension to build the program.
  2. If you're using CLion, you can open the project directly to build the program.

Using VSCode or CLion for regular development is recommended.

Debug

Install Debug Tools if you need.

brew install lldb # macOS
sudo apt install lldb # Ubuntu

If you're using VSCode, you can use the C/C++ and Code LLDB extension to debug.

Tests

Average memory statistics for 75250 tests:

NAME                    COUNT     SIZE
memory allocated         1011   124975  (123.6 per block)
memory used               967   117030  (0 overhead, 8.2 average slack)
atoms                     532    26858  (50.5 per atom)
objects                   172    12425  (72.2 per object)
properties              876    15798  (5.1 per object)
shapes                   60    13809  (230.2 per shape)
bytecode functions         13     1685
bytecode                 13      931  (71.6 per function)
C functions               100
arrays                      1
fast arrays               1
elements                  1       16  (1.0 per fast array)

Result: 515/75250 errors, 1392 excluded, 7972 skipped, 515 new

Benchmark

  • Apple M1 Pro
  • macOS Monterey 12.2.1
  • Clang 13.0.0 arm64-apple-darwin21.3.0
bellard/quickjs (2788d71) openwebf/quickjs (latest)
Richards 1188 1457
Crypto 1443 1527
RayTrace 744 1995
NavierStokes 2775 2979
DeltaBlue 1100 1595
Total score 1312 1840 (+40.2%)
File Size(KB) 1.3M 1.4M

quickjs's People

Contributors

shiqimei avatar

Stargazers

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

Watchers

 avatar

quickjs's Issues

Original QuickJS Notes

TODO

Bugs: - modules: better error handling with cyclic module references

Misc ideas:

  • use custom printf to avoid compatibility issues with floating point numbers
  • consistent naming for preprocessor defines
  • unify coding style and naming conventions
  • use names from the ECMA spec in library implementation
  • use byte code emitters with typed arguments (for clarity)
  • use 2 bytecode DynBufs in JSFunctionDef, one for reading, one for writing
    and use the same wrappers in all phases
  • use more generic method for line numbers in resolve_variables and resolve_labels
  • use custom timezone support to avoid C library compatibility issues

Memory:

  • use memory pools for objects, etc?
  • test border cases for max number of atoms, object properties, string length
  • add emergency malloc mode for out of memory exceptions.
  • test all DynBuf memory errors
  • test all js_realloc memory errors
  • improve JS_ComputeMemoryUsage() with more info

Built-in standard library:

  • BSD sockets
  • modules: use realpath in module name normalizer and put it in quickjs-libc
  • modules: if no ".", use a well known module loading path ?
  • get rid of __loadScript, use more common name

REPL:

  • debugger
  • readline: support MS Windows terminal
  • readline: handle dynamic terminal resizing
  • readline: handle double width unicode characters
  • multiline editing
  • runtime object and function inspectors
  • interactive object browser
  • use more generic approach to display evaluation results
  • improve directive handling: dispatch, colorize, completion...
  • save history
  • close all predefined methods in repl.js and jscalc.js

Optimization ideas:

  • 64-bit atoms in 64-bit mode ?
  • 64-bit small bigint in 64-bit mode ?
  • reuse stack slots for disjoint scopes, if strip
  • add heuristic to avoid some cycles in closures
  • small String (0-2 charcodes) with immediate storage
  • perform static string concatenation at compile time
  • optimize string concatenation with ropes or miniropes?
  • add implicit numeric strings for Uint32 numbers?
  • optimize s += a + b, s += a.b and similar simple expressions
  • ensure string canonical representation and optimise comparisons and hashes?
  • remove JSObject.first_weak_ref, use bit+context based hashed array for weak references
  • property access optimization on the global object, functions,
    prototypes and special non extensible objects.
  • create object literals with the correct length by backpatching length argument
  • remove redundant set_loc_uninitialized/check_uninitialized opcodes
  • peephole optim: push_atom_value, to_propkey -> push_atom_value
  • peephole optim: put_loc x, get_loc_check x -> set_loc x
  • convert slow array to fast array when all properties != length are numeric
  • optimize destructuring assignments for global and local variables
  • implement some form of tail-call-optimization
  • optimize OP_apply
  • optimize f(...b)

Test262o: 0/11262 errors, 463 excluded
Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch)

Result: 35/75280 errors, 909 excluded, 585 skipped
Test262 commit: 31126581e7290f9233c29cefd93f66c6ac78f1c9

VERSION 2021-03-27
Changelog 2021-03-27:
  • faster Array.prototype.push and Array.prototype.unshift
  • added JS_UpdateStackTop()
  • fixed Windows console
  • misc bug fixes

2020-11-08:

  • improved function parameter initializers
  • added std.setenv(), std.unsetenv() and std.getenviron()
  • added JS_EvalThis()
  • misc bug fixes

2020-09-06:

  • added logical assignment operators
  • added IsHTMLDDA support
  • faster for-of loops
  • os.Worker now takes a module filename as parameter
  • qjsc: added -D option to compile dynamically loaded modules or workers
  • misc bug fixes

2020-07-05:

  • modified JS_GetPrototype() to return a live value
  • REPL: support unicode characters larger than 16 bits
  • added os.Worker
  • improved object serialization
  • added std.parseExtJSON
  • misc bug fixes

2020-04-12:

  • added cross realm support
  • added AggregateError and Promise.any
  • added env, uid and gid options in os.exec()
  • misc bug fixes

2020-03-16:

  • reworked error handling in std and os libraries: suppressed I/O
    exceptions in std FILE functions and return a positive errno value
    when it is explicit
  • output exception messages to stderr
  • added std.loadFile(), std.strerror(), std.FILE.prototype.tello()
  • added JS_GetRuntimeOpaque(), JS_SetRuntimeOpaque(), JS_NewUint32()
  • updated to Unicode 13.0.0
  • misc bug fixes

2020-01-19:

  • keep CONFIG_BIGNUM in the makefile
  • added os.chdir()
  • qjs: added -I option
  • more memory checks in the bignum operations
  • modified operator overloading semantics to be closer to the TC39
    proposal
  • suppressed "use bigint" mode. Simplified "use math" mode
  • BigDecimal: changed suffix from 'd' to 'm'
  • misc bug fixes

2020-01-05:

  • always compile the bignum code. Added '--bignum' option to qjs.
  • added BigDecimal
  • added String.prototype.replaceAll
  • misc bug fixes

2019-12-21:

  • added nullish coalescing operator (ES2020)
  • added optional chaining (ES2020)
  • removed recursions in garbage collector
  • test stack overflow in the parser
  • improved backtrace logic
  • added JS_SetHostPromiseRejectionTracker()
  • allow exotic constructors
  • improved c++ compatibility
  • misc bug fixes

2019-10-27:

  • added example of C class in a module (examples/test_point.js)
  • added JS_GetTypedArrayBuffer()
  • misc bug fixes

2019-09-18:

  • added os.exec and other system calls
  • exported JS_ValueToAtom()
  • qjsc: added 'qjsc_' prefix to the generated C identifiers
  • added cross-compilation support
  • misc bug fixes

2019-09-01:

  • added globalThis
  • documented JS_EVAL_FLAG_COMPILE_ONLY
  • added import.meta.url and import.meta.main
  • added 'debugger' statement
  • misc bug fixes

2019-08-18:

  • added os.realpath, os.getcwd, os.mkdir, os.stat, os.lstat,
    os.readlink, os.readdir, os.utimes, std.popen
  • module autodetection
  • added import.meta
  • misc bug fixes

2019-08-10:

  • added public class fields and private class fields, methods and
    accessors (TC39 proposal)
  • changed JS_ToCStringLen() prototype
  • qjsc: handle '-' in module names and modules with the same filename
  • added std.urlGet
  • exported JS_GetOwnPropertyNames() and JS_GetOwnProperty()
  • exported some bigint C functions
  • added support for eshost in run-test262
  • misc bug fixes

2019-07-28:

  • added dynamic import
  • added Promise.allSettled
  • added String.prototype.matchAll
  • added Object.fromEntries
  • reduced number of ticks in await
  • added BigInt support in Atomics
  • exported JS_NewPromiseCapability()
  • misc async function and async generator fixes
  • enabled hashbang support by default

2019-07-21:

  • updated test262 tests
  • updated to Unicode version 12.1.0
  • fixed missing Date object in qjsc
  • fixed multi-context creation
  • misc ES2020 related fixes
  • simplified power and division operators in bignum extension
  • fixed several crash conditions

2019-07-09:

  • first public release

QuickJS build failed - Ubuntu20 : trying to find `rustc`

Trying to build quickjs on ubuntu20. Getting the following error on two different ubuntu instances.

cmake and ninja install was successful.
sudo apt install cmake ninja-build # Ubuntu

quickjs > bash scripts/build.sh # build quickjs qjs qjsc etc.                      ~/code/js/quickjs:@sparta 11:12
+ rm -rf build bin lib
+ mkdir build
+ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -B build -S .
-- The C compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at build/_deps/corrosion-src/cmake/FindRust.cmake:21 (message):
  `rustc` not found in PATH or `/home/towshif/.cargo/bin`.

  Hint: Check if `rustc` is in PATH or manually specify the location by
  setting `Rust_COMPILER` to the path to `rustc`.
Call Stack (most recent call first):
  build/_deps/corrosion-src/cmake/FindRust.cmake:259 (_findrust_failed)
  build/_deps/corrosion-src/cmake/Corrosion.cmake:57 (find_package)
  build/_deps/corrosion-src/CMakeLists.txt:68 (include)


-- Configuring incomplete, errors occurred!
See also "/home/towshif/code/js/quickjs/build/CMakeFiles/CMakeOutput.log".
+ cmake --build ./build --target qjs run-test262 -j 8
ninja: error: loading 'build.ninja': No such file or directory

Array.prototype.indexOf.call

test262/test/built-ins/Array/prototype/indexOf/15.4.4.14-1-8.js:9: strict mode: unexpected error: Test262Error: Array.prototype.indexOf.call(obj, "l") Expected SameValue(«-1», «2») to be true
test262/test/built-ins/Array/prototype/indexOf/15.4.4.14-2-18.js:11: unexpected error: Test262Error: Array.prototype.indexOf.call(str, "2") Expected SameValue(«-1», «2») to be true
test262/test/built-ins/Array/prototype/indexOf/15.4.4.14-2-18.js:11: strict mode: unexpected error: Test262Error: Array.prototype.indexOf.call(str, "2") Expected SameValue(«-1», «2») to be true
test262/test/built-ins/Array/prototype/indexOf/15.4.4.14-3-14.js:16: unexpected error: Test262Error: Array.prototype.indexOf.call(objOne, true) Expected SameValue(«-1», «0») to be true
test262/test/built-ins/Array/prototype/indexOf/15.4.4.14-3-14.js:16: strict mode: unexpected error: Test262Error: Array.prototype.indexOf.call(objOne, true) Expected SameValue(«-1», «0») to be true

JS_FreeRuntime: Assertion `list_empty(&rt->gc_obj_list)' failed.

Run ./bin/qjs -e 'console.log("Hello, World!")'
qjs: /home/runner/work/quickjs/quickjs/src/core/runtime.c:2672: JS_FreeRuntime: Assertion `list_empty(&rt->gc_obj_list)' failed.
/home/runner/work/_temp/3c25e719-61b9-46be-ad45-fb3e90ec798b.sh: line 1: 2445 Aborted (core dumped) ./bin/qjs -e 'console.log("Hello, World!")'
Error: Process completed with exit code 134.

Improve ECMA262 Tests

Before

Average memory statistics for 75250 tests:

NAME                    COUNT     SIZE
memory allocated         1011   124975  (123.6 per block)
memory used               967   117030  (0 overhead, 8.2 average slack)
atoms                     532    26858  (50.5 per atom)
objects                   172    12425  (72.2 per object)
properties              876    15798  (5.1 per object)
shapes                   60    13809  (230.2 per shape)
bytecode functions         13     1685
bytecode                 13      931  (71.6 per function)
C functions               100
arrays                      1
fast arrays               1
elements                  1       16  (1.0 per fast array)

Result: 515/75250 errors, 1392 excluded, 7972 skipped, 515 new

After

Average memory statistics for 75820 tests:

NAME                    COUNT     SIZE
memory allocated         1015   139033  (137.0 per block)
memory used               971   116989  (0 overhead, 22.7 average slack)
atoms                     536    27003  (50.4 per atom)
objects                   172    12433  (72.3 per object)
  properties              877    15829  (5.1 per object)
  shapes                   60    13821  (230.3 per shape)
bytecode functions         13     1699
  bytecode                 13      975  (75.0 per function)
C functions               100
arrays                      1
  fast arrays               1
  elements                  1       16  (1.0 per fast array)

Result: 1368/75820 errors, 9368 skipped, 1368 new

Actions

  1. Lock and freeze test262 commit and make it a submodule, or the total tests count increase time by time, not good for compare test reulsts before/after code changes; We upgrade test262 submodule periodically;
  2. Record error test count, warning if code changes introduce new bugs.

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.