10000 the plan for sablejs 2.0 · Issue #19 · sablejs/sablejs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

the plan for sablejs 2.0 #19

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
ErosZy opened this issue Oct 28, 2021 · 9 comments
Open

the plan for sablejs 2.0 #19

ErosZy opened this issue Oct 28, 2021 · 9 comments

Comments

@ErosZy
Copy link
Member
ErosZy commented Oct 28, 2021

sablejs 1.x has been running well on YoTest, but because of the private opcode design, we don't open all code for community(preventing decompiling). After discussions, sablejs 2.0 will plan to open all code! To reach this goal, we will make a major upgrade to the current code of 1.x, include:

1. remove the private opcode design and transform for the stack operation directly
2. dynamically import inner object for sandbox

1. Transform Directly

Since sablejs 1.x is fully stack-based vm, we will have a big loop to execute the relevant opcode code. However, this approach causes a significant performance loss due to the failure of branch prediction:

for (;;) {
  switch (opcode) {
    case 0: {
      // ...
    }
    case 1: {
      // ...
    }
    case 2: {
      // ...
    }
  }
}

After using the latest d8 and perf for profiling, about 30% of the performance consumption is wasted. To solve this problem, and to make V8 better able to help us with JIT, we will perform the equivalent transform operation directly, consider the following example:

function add() {
  return 1 + 2 + 3;
}

In 1.x, we will get linear opcode bytes, which will then be executed by vm. But in 2.0, we will compile directly to the following code:

function __C_add(J) {
  __pushNumber(J, 1);
  __pushNumber(J, 2);
  __R_add(J);
  __pushNumber(J, 3);
  __R_add(J);
}

Here, stack manipulation methods such as __pushNumber are still provided by runtime. In this way, together with the relevant compilation optimizations in 1.x, there will be a relatively large performance improvment for frequent execution(benchmark can be followed by DoppioJVM Web JIT implement).

(function(){
  for(var i = 0; i < 10000000; i++);
}());

// sablejs 2.0: 276.279ms --- baseline
// sablejs 1.0.6 878ms --- slower: 218.11%
// quickjs-wasm: 228ms --- faster: 17.39%

At the same time, this brings the benefit of not having to rely on opcode, so we can directly open all of sablejs's code.

2. Dynamically Import Inner Object

In most of the usage of the current feedback, it is basically using sablejs for JSVMP. But sablejs 1.x is mainly designed with sandbox as the core, after 2.0 we will mainly aim at JSVMP while taking into account the functionality of sandbox,(the Inner Object will be import on demand according to your needs).

Also, when you are using JSVMP only, sablejs 2.0 will get a very big performance improvment thanks to V8's object optimization!

I considered for releasing sablejs 2.0 in mid-2022, please look forward to it! 😁

@ErosZy ErosZy pinned this issue Oct 28, 2021
@ErosZy ErosZy changed the title Plan for sablejs 2.0 sablejs 2.0 plan Oct 28, 2021
@ErosZy ErosZy changed the title sablejs 2.0 plan the plan for sablejs 2.0 Oct 28, 2021
@fabiospampinato
Copy link
fabiospampinato 8000 commented Jan 12, 2022

Will v2 include the ability to evaluate a raw javascript string without compiling it at build times first? That seems a big limitation at the moment if the goal of the project is to be able to be used as a secure vm for plugins.

@ErosZy
Copy link
Member Author
ErosZy commented Jan 12, 2022

@fabiospampinato If the compiler is included, then there is a risk of being decompiled, and there should be no plans to put the compiler and interpreter together at this time.

@npc1054657282
Copy link

Hello, will sablejs-2.0 support some new features in ES2016+?
I'm a ES2016+ user. I'd like to try the product, but some features like 'bigint' cannot be translated to ES2015 by babel.

@ErosZy
Copy link
Member Author
ErosZy commented Mar 15, 2022

@npc1054657282 maybe not, i have little time to maintance this project, but you can add es2016+ features by yourself when 2.0 released.

@Foolyou
Copy link
Foolyou commented May 31, 2022

Great work! I have two questions:
Is the code transformed by the direct transform method eventually executed by an eval(or new Function call)? Does this mean we cannot use sable2.x in an eval-forbidding environment?

@ErosZy
Copy link
Member Author
ErosZy commented Jun 1, 2022

Great work! I have two questions: Is the code transformed by the direct transform method eventually executed by an eval(or new Function call)? Does this mean we cannot use sable2.x in an eval-forbidding environment?

No, it still runs with stack ops, don't need eval or new Funcation. But maybe the schedule will be late, i'm really really busy and have no passion for 2.0 implementation. At the same time, i learn some optimization from v8, i think it will faster than i think before. But it needs some time.

@AngusFu
Copy link
AngusFu commented Mar 21, 2023

Any progress?

@250king
Copy link
250king commented Jul 13, 2023

I have same question about the progress(

@HackerYunen
Copy link

有生之年系列+1 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
0