Skip to content
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

Remove control slice from ops #6048

Merged
merged 9 commits into from
Jul 8, 2020
Merged

Remove control slice from ops #6048

merged 9 commits into from
Jul 8, 2020

Conversation

SyrupThinker
Copy link
Contributor

@SyrupThinker SyrupThinker commented Jun 2, 2020

Observation

The control slice is special cased in the dispatch interface despite it being treated similar to zero copy buffers internally.

Does the interface benefit from this distinction, or should it be removed for simplicity?

After this maybe we can explore removing the control buffer to simplify the interface further, using only zero copy bufs.
ry


Points that need to be addressed in the implementation of this PR

  • The DenoCore interface now has two identical functions dispatch and send
    One could be removed.
  • Is the distinction of control and data bytes still appropriate for the Metrics? The PR currently merges them. This changes the stable public interface, so it might be undesired.
  • How many ZeroCopyBufs should be stack allocated?
    I'm currently planning on measuring the frequency of buffer counts for different workloads to determine this.

@SyrupThinker SyrupThinker marked this pull request as ready for review June 3, 2020 12:48
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting! We need to be extremely careful with this patch - since it effects everything - do you have any ideas about the perf impact?

cli/js/lib.deno.ns.d.ts Outdated Show resolved Hide resolved
@SyrupThinker
Copy link
Contributor Author

do you have any ideas about the perf impact?

I think the benchmarks should go together with frequency analysis; I'll probably do that later today or tomorrow.

@bartlomieju bartlomieju added cli related to cli/ dir deno_core Changes in "deno_core" crate are needed perf performance related labels Jun 3, 2020
@SyrupThinker
Copy link
Contributor Author

Benchmarks
--- error_001 ---
┌───────┬───────────┬──────────────────────┬───────────────────────┐
│ (idx) │   name    │         mean         │        stddev         │
├───────┼───────────┼──────────────────────┼───────────────────────┤
│   0   │ "stack_0" │ 0.016861711716290324 │ 0.001209008600273871  │
│   1   │ "master"  │ 0.019731050206363634 │ 0.0012051073669040921 │
│   2   │ "stack_1" │ 0.020213051887313434 │ 0.0013331327769872552 │
│   3   │ "stack_3" │ 0.020432211214075627 │ 0.0017623497958508848 │
│   4   │ "stack_2" │ 0.021670581789062487 │ 0.002620364198727666  │
└───────┴───────────┴──────────────────────┴───────────────────────┘
--- text_decoder ---
┌───────┬───────────┬─────────────────────┬──────────────────────┐
│ (idx) │   name    │        mean         │        stddev        │
├───────┼───────────┼─────────────────────┼──────────────────────┤
│   0   │ "stack_2" │ 0.10694174014673916 │ 0.00872960419621517  │
│   1   │ "stack_3" │ 0.1137201812392857  │ 0.031673157672947476 │
│   2   │ "stack_0" │ 0.12616989255500002 │ 0.046129597432469374 │
│   3   │ "master"  │ 0.12869162557862068 │ 0.04715683379998145  │
│   4   │ "stack_1" │ 0.12871970084999998 │ 0.03823356311246889  │
└───────┴───────────┴─────────────────────┴──────────────────────┘
--- text_encoder ---
┌───────┬───────────┬─────────────────────┬──────────────────────┐
│ (idx) │   name    │        mean         │        stddev        │
├───────┼───────────┼─────────────────────┼──────────────────────┤
│   0   │ "stack_1" │ 0.0717044250264706  │ 0.006757405839083842 │
│   1   │ "master"  │ 0.07936682638756758 │ 0.01821966260741203  │
│   2   │ "stack_2" │ 0.08608793195833335 │ 0.02686722169764651  │
│   3   │ "stack_0" │ 0.09973237055499998 │ 0.05343353912971864  │
│   4   │ "stack_3" │ 0.10999774889642855 │  0.0818547558818851  │
└───────┴───────────┴─────────────────────┴──────────────────────┘
--- cold_relative_import ---
┌───────┬───────────┬─────────────────────┬──────────────────────┐
│ (idx) │   name    │        mean         │        stddev        │
├───────┼───────────┼─────────────────────┼──────────────────────┤
│   0   │ "stack_1" │ 0.48369723555000005 │ 0.021724634325360637 │
│   1   │ "master"  │ 0.48557721312000013 │ 0.012963487337691326 │
│   2   │ "stack_0" │ 0.48703590865500007 │  0.0336401666101215  │
│   3   │ "stack_3" │ 0.5827686885250001  │  0.0933026463407021  │
│   4   │ "stack_2" │ 0.6147542190250002  │ 0.30426511396283057  │
└───────┴───────────┴─────────────────────┴──────────────────────┘
--- cold_hello ---
┌───────┬───────────┬────────────────────┬──────────────────────┐
│ (idx) │   name    │        mean        │        stddev        │
├───────┼───────────┼────────────────────┼──────────────────────┤
│   0   │ "stack_2" │   0.475347581525   │ 0.012685799647242006 │
│   1   │ "master"  │   0.47537249112    │ 0.013647874221267235 │
│   2   │ "stack_1" │ 0.4932233829500001 │ 0.03118481793084088  │
│   3   │ "stack_3" │ 0.5116719161250001 │ 0.09601342753917451  │
│   4   │ "stack_0" │   0.541078841355   │ 0.08287149799291146  │
└───────┴───────────┴────────────────────┴──────────────────────┘
--- workers_round_robin ---
┌───────┬───────────┬─────────────────────┬──────────────────────┐
│ (idx) │   name    │        mean         │        stddev        │
├───────┼───────────┼─────────────────────┼──────────────────────┤
│   0   │ "stack_0" │ 0.24092560588833334 │ 0.01522774066166062  │
│   1   │ "master"  │ 0.24289162690333335 │ 0.005285363978466811 │
│   2   │ "stack_2" │ 0.24396237395833334 │ 0.00803912282210745  │
│   3   │ "stack_3" │ 0.24751076943409095 │ 0.007318199174590021 │
│   4   │ "stack_1" │ 0.24863461166818182 │ 0.004995343173427268 │
└───────┴───────────┴─────────────────────┴──────────────────────┘
--- relative_import ---
┌───────┬───────────┬──────────────────────┬───────────────────────┐
│ (idx) │   name    │         mean         │        stddev         │
├───────┼───────────┼──────────────────────┼───────────────────────┤
│   0   │ "stack_0" │ 0.01591655601445946  │ 0.002001526030374305  │
│   1   │ "master"  │ 0.01823087436961833  │ 0.001804755798761421  │
│   2   │ "stack_3" │ 0.018383101556007753 │  0.00185009939154322  │
│   3   │ "stack_1" │ 0.01923898110675676  │ 0.0020232794975189867 │
│   4   │ "stack_2" │ 0.019758953217920355 │ 0.002556569904024987  │
└───────┴───────────┴──────────────────────┴───────────────────────┘
--- workers_startup ---
┌───────┬───────────┬────────────────────┬──────────────────────┐
│ (idx) │   name    │        mean        │        stddev        │
├───────┼───────────┼────────────────────┼──────────────────────┤
│   0   │ "stack_2" │   0.566072217325   │ 0.019350146350982325 │
│   1   │ "stack_0" │   0.586667706155   │ 0.10281441044382549  │
│   2   │ "stack_3" │ 0.5979343384250001 │ 0.15339802273211597  │
│   3   │ "master"  │ 0.6104044733199999 │ 0.06354807826800431  │
│   4   │ "stack_1" │ 0.6152848146500001 │ 0.05693548775843995  │
└───────┴───────────┴────────────────────┴──────────────────────┘
--- hello ---
┌───────┬───────────┬──────────────────────┬───────────────────────┐
│ (idx) │   name    │         mean         │        stddev         │
├───────┼───────────┼──────────────────────┼───────────────────────┤
│   0   │ "stack_0" │ 0.016802109671666673 │ 0.005694779322814975  │
│   1   │ "master"  │ 0.018582407160277772 │ 0.0021273691289819653 │
│   2   │ "stack_1" │ 0.01880988423655463  │ 0.0018087663755995485 │
│   3   │ "stack_2" │ 0.019302377868478264 │ 0.002097364295183566  │
│   4   │ "stack_3" │ 0.020478759979545468 │ 0.005190708798191717  │
└───────┴───────────┴──────────────────────┴───────────────────────┘
--- deno_tcp ---
┌───────┬───────────┬─────────────┬─────────────┐
│ (idx) │   name    │ req_per_sec │ max_latency │
├───────┼───────────┼─────────────┼─────────────┤
│   0   │ "stack_0" │    49894    │     0.4     │
│   1   │ "stack_1" │    49110    │    0.417    │
│   2   │ "stack_2" │    48607    │    0.427    │
│   3   │ "master"  │    47888    │    0.454    │
│   4   │ "stack_3" │    42108    │    0.522    │
└───────┴───────────┴─────────────┴─────────────┘
--- deno_core_http_bench ---
┌───────┬───────────┬─────────────┬─────────────┐
│ (idx) │   name    │ req_per_sec │ max_latency │
├───────┼───────────┼─────────────┼─────────────┤
│   0   │ "stack_2" │    56210    │    0.314    │
│   1   │ "master"  │    56062    │    0.325    │
│   2   │ "stack_1" │    55442    │    0.314    │
│   3   │ "stack_0" │    49543    │    0.409    │
│   4   │ "stack_3" │    47874    │    0.396    │
└───────┴───────────┴─────────────┴─────────────┘
--- node_proxy_tcp ---
┌───────┬───────────┬─────────────┬─────────────┐
│ (idx) │   name    │ req_per_sec │ max_latency │
├───────┼───────────┼─────────────┼─────────────┤
│   0   │ "stack_0" │    22037    │    0.764    │
│   1   │ "stack_1" │    21096    │    0.803    │
│   2   │ "stack_2" │    20913    │    0.804    │
│   3   │ "master"  │    20575    │    0.835    │
│   4   │ "stack_3" │    19327    │    1.05     │
└───────┴───────────┴─────────────┴─────────────┘
--- deno_proxy_tcp ---
┌───────┬───────────┬─────────────┬─────────────┐
│ (idx) │   name    │ req_per_sec │ max_latency │
├───────┼───────────┼─────────────┼─────────────┤
│   0   │ "stack_2" │    19043    │    0.88     │
│   1   │ "stack_0" │    18804    │    0.89     │
│   2   │ "master"  │    18443    │    0.92     │
│   3   │ "stack_1" │    17957    │    1.01     │
│   4   │ "stack_3" │    17008    │    1.32     │
└───────┴───────────┴─────────────┴─────────────┘
--- hyper ---
┌───────┬───────────┬─────────────┬─────────────┐
│ (idx) │   name    │ req_per_sec │ max_latency │
├───────┼───────────┼─────────────┼─────────────┤
│   0   │ "stack_3" │    59028    │    0.238    │
│   1   │ "stack_2" │    58759    │    0.272    │
│   2   │ "master"  │    58169    │    0.284    │
│   3   │ "stack_0" │    58123    │    0.308    │
│   4   │ "stack_1" │    57202    │    0.311    │
└───────┴───────────┴─────────────┴─────────────┘
--- node_tcp ---
┌───────┬───────────┬─────────────┬─────────────┐
│ (idx) │   name    │ req_per_sec │ max_latency │
├───────┼───────────┼─────────────┼─────────────┤
│   0   │ "stack_2" │    60537    │    0.348    │
│   1   │ "stack_0" │    60196    │    0.352    │
│   2   │ "stack_1" │    58752    │    0.393    │
│   3   │ "master"  │    57119    │    0.424    │
│   4   │ "stack_3" │    57007    │    0.471    │
└───────┴───────────┴─────────────┴─────────────┘
--- deno_http ---
┌───────┬───────────┬─────────────┬─────────────┐
│ (idx) │   name    │ req_per_sec │ max_latency │
├───────┼───────────┼─────────────┼─────────────┤
│   0   │ "master"  │    22315    │    0.97     │
│   1   │ "stack_2" │    21208    │    1.84     │
│   2   │ "stack_1" │    21152    │    1.08     │
│   3   │ "stack_0" │    21024    │    1.07     │
│   4   │ "stack_3" │    18523    │    1.18     │
└───────┴───────────┴─────────────┴─────────────┘
--- node_http ---
┌───────┬───────────┬─────────────┬─────────────┐
│ (idx) │   name    │ req_per_sec │ max_latency │
├───────┼───────────┼─────────────┼─────────────┤
│   0   │ "stack_0" │    34326    │    0.688    │
│   1   │ "stack_1" │    34208    │    0.796    │
│   2   │ "master"  │    33735    │    0.775    │
│   3   │ "stack_2" │    31879    │    0.846    │
│   4   │ "stack_3" │    28429    │    0.93     │
└───────┴───────────┴─────────────┴─────────────┘
--- node_proxy ---
┌───────┬───────────┬─────────────┬─────────────┐
│ (idx) │   name    │ req_per_sec │ max_latency │
├───────┼───────────┼─────────────┼─────────────┤
│   0   │ "stack_0" │    3675     │    4.86     │
│   1   │ "stack_1" │    3661     │    4.88     │
│   2   │ "master"  │    3656     │    5.01     │
│   3   │ "stack_2" │    3624     │    5.37     │
│   4   │ "stack_3" │    3140     │    6.25     │
└───────┴───────────┴─────────────┴─────────────┘
--- error_001 ---
┌───────┬───────────┬────────────┐
│ (idx) │   name    │ max_memory │
├───────┼───────────┼────────────┤
│   0   │ "stack_1" │  23080960  │
│   1   │ "stack_3" │  23085056  │
│   2   │ "stack_0" │  23121920  │
│   3   │ "stack_2" │  23138304  │
│   4   │ "master"  │  23670784  │
└───────┴───────────┴────────────┘
--- text_decoder ---
┌───────┬───────────┬────────────┐
│ (idx) │   name    │ max_memory │
├───────┼───────────┼────────────┤
│   0   │ "stack_2" │  27475968  │
│   1   │ "stack_3" │  27492352  │
│   2   │ "master"  │  27570176  │
│   3   │ "stack_1" │  27713536  │
│   4   │ "stack_0" │  27869184  │
└───────┴───────────┴────────────┘
--- text_encoder ---
┌───────┬───────────┬────────────┐
│ (idx) │   name    │ max_memory │
├───────┼───────────┼────────────┤
│   0   │ "stack_1" │  33079296  │
│   1   │ "master"  │  33181696  │
│   2   │ "stack_0" │  33296384  │
│   3   │ "stack_2" │  33824768  │
│   4   │ "stack_3" │  33869824  │
└───────┴───────────┴────────────┘
--- cold_relative_import ---
┌───────┬───────────┬────────────┐
│ (idx) │   name    │ max_memory │
├───────┼───────────┼────────────┤
│   0   │ "stack_2" │  79745024  │
│   1   │ "stack_0" │  79880192  │
│   2   │ "stack_3" │  80650240  │
│   3   │ "stack_1" │  81059840  │
│   4   │ "master"  │  81805312  │
└───────┴───────────┴────────────┘
--- cold_hello ---
┌───────┬───────────┬────────────┐
│ (idx) │   name    │ max_memory │
├───────┼───────────┼────────────┤
│   0   │ "stack_0" │  78282752  │
│   1   │ "stack_1" │  78684160  │
│   2   │ "stack_2" │  80023552  │
│   3   │ "master"  │  80080896  │
│   4   │ "stack_3" │  80740352  │
└───────┴───────────┴────────────┘
--- workers_round_robin ---
┌───────┬───────────┬────────────┐
│ (idx) │   name    │ max_memory │
├───────┼───────────┼────────────┤
│   0   │ "master"  │  46473216  │
│   1   │ "stack_3" │  46759936  │
│   2   │ "stack_0" │  46952448  │
│   3   │ "stack_1" │  47005696  │
│   4   │ "stack_2" │  47120384  │
└───────┴───────────┴────────────┘
--- relative_import ---
┌───────┬───────────┬────────────┐
│ (idx) │   name    │ max_memory │
├───────┼───────────┼────────────┤
│   0   │ "stack_1" │  23080960  │
│   1   │ "stack_3" │  23085056  │
│   2   │ "stack_0" │  23121920  │
│   3   │ "stack_2" │  23138304  │
│   4   │ "master"  │  23670784  │
└───────┴───────────┴────────────┘
--- workers_startup ---
┌───────┬───────────┬────────────┐
│ (idx) │   name    │ max_memory │
├───────┼───────────┼────────────┤
│   0   │ "stack_1" │ 207949824  │
│   1   │ "stack_0" │ 208015360  │
│   2   │ "stack_2" │ 208101376  │
│   3   │ "master"  │ 208347136  │
│   4   │ "stack_3" │ 208424960  │
└───────┴───────────┴────────────┘
--- hello ---
┌───────┬───────────┬────────────┐
│ (idx) │   name    │ max_memory │
├───────┼───────────┼────────────┤
│   0   │ "master"  │  22450176  │
│   1   │ "stack_0" │  22552576  │
│   2   │ "stack_1" │  22679552  │
│   3   │ "stack_2" │  22769664  │
│   4   │ "stack_3" │  22978560  │
└───────┴───────────┴────────────┘
zero_copy length counts for different programs

Fetch remote images and store them to disk

Initial fetch

┌─────────────────────────┬───┬─────┬──────┬───┬────────────┐
│          (idx)          │ 0 │  1  │  2   │ 3 │   Values   │
├─────────────────────────┼───┼─────┼──────┼───┼────────────┤
│      zeroCopyCount      │ 0 │ 142 │ 1909 │ 0 │           │
└─────────────────────────┴───┴─────┴──────┴───┴───────────┘
│      zeroCopyCount      │ 0 │ 338 │ 8646 │ 0 │            │
└─────────────────────────┴───┴─────┴──────┴───┴────────────┘

Check for new images to fetch (none added)

┌─────────────────────────┬───┬─────┬──────┬───┬───────────┐
│          (idx)          │ 0 │  1  │  2   │ 3 │  Values   │
├─────────────────────────┼───┼─────┼──────┼───┼───────────┤
│      zeroCopyCount      │ 0 │ 142 │ 1909 │ 0 │           │
└─────────────────────────┴───┴─────┴──────┴───┴───────────┘
│      zeroCopyCount      │ 0 │ 242 │ 3394 │ 0 │           │
└─────────────────────────┴───┴─────┴──────┴───┴───────────┘

Single fetch and display processed data

┌─────────────────────────┬───┬───┬────┬───┬────────┐
│          (idx)          │ 0 │ 1 │ 2  │ 3 │ Values │
├─────────────────────────┼───┼───┼────┼───┼────────┤
│      zeroCopyCount      │ 0 │ 3 │ 11 │ 0 │        │
└─────────────────────────┴───┴───┴────┴───┴────────┘

Oak's getting started returning JSON.stringify(Deno.metrics()) as the body

After several requests.

┌─────────────────────────┬───┬────┬────┬───┬────────┐
│          (idx)          │ 0 │ 1  │ 2  │ 3 │ Values │
├─────────────────────────┼───┼────┼────┼───┼────────┤
│      zeroCopyCount      │ 0 │ 16 │ 13 │ 0 │        │
└─────────────────────────┴───┴────┴────┴───┴────────┘

The script that generated the benchmark tables

┌─────────────────────────┬───┬────┬────┬───┬────────┐
│          (idx)          │ 0 │ 1  │ 2  │ 3 │ Values │
├─────────────────────────┼───┼────┼────┼───┼────────┤
│      zeroCopyCount      │ 0 │ 12 │ 20 │ 0 │        │
└─────────────────────────┴───┴────┴────┴───┴────────┘

There is no obvious performance impact in the synthetic benchmarks.
Although if someone could do the benchmark on a dedicated system to reduce noise that would be great.

Stack allocation should be done for at least 2 buffers because those are predominant in IO heavy tasks.
I think this value should be revisited at a later time when the plug-in ecosystem can be taken into consideration.

core/bindings.rs Outdated Show resolved Hide resolved
core/bindings.rs Outdated Show resolved Hide resolved
Copy link
Member

@piscisaureus piscisaureus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I think we should rename ZeroCopyBuf to JSBuf or something because it is a bit misleading now (doesn't have to be done in this patch).

Also we should probably document that ops shouldn't clone and store zero_copy[0] because it might be overwritten immediately.

@ry PTAL

@piscisaureus piscisaureus requested a review from ry June 5, 2020 14:12
@SyrupThinker
Copy link
Contributor Author

Deno.core.dispatch and Deno.core.send haven't been addressed yet. They do the same thing, should one be removed?

@ry
Copy link
Member

ry commented Jun 5, 2020

master:

  "req_per_sec": {
    "deno_tcp": 50864, 
    "deno_core_http_bench": 65345, 
    "node_proxy_tcp": 28062, 
    "deno_proxy_tcp": 20900, 
    "hyper": 55173, 
    "node_tcp": 57598, 
    "deno_http": 18800, 
    "node_http": 17621, 
    "node_proxy": 3044
  }, 
  "max_latency": {
    "deno_tcp": 1.37, 
    "deno_core_http_bench": 0.819, 
    "node_proxy_tcp": 1.79, 
    "deno_proxy_tcp": 2.27, 
    "hyper": 0.578, 
    "node_tcp": 1.26, 
    "deno_http": 1.66, 
    "node_http": 3.13, 
    "node_proxy": 8.88
  }, 

this branch try 1

  "req_per_sec": {
    "deno_tcp": 54077, 
    "deno_core_http_bench": 67802, 
    "node_proxy_tcp": 27119, 
    "deno_proxy_tcp": 22084, 
    "hyper": 53427, 
    "node_tcp": 46011, 
    "deno_http": 20364, 
    "node_http": 21039, 
    "node_proxy": 3126
  }, 
  "max_latency": {
    "deno_tcp": 1.0, 
    "deno_core_http_bench": 1.17, 
    "node_proxy_tcp": 1.88, 
    "deno_proxy_tcp": 2.07, 
    "hyper": 0.544, 
    "node_tcp": 2.64, 
    "deno_http": 1.46, 
    "node_http": 2.46, 
    "node_proxy": 8.31
  }, 

this branch try 2

  "req_per_sec": {
    "deno_tcp": 62188, 
    "deno_core_http_bench": 76555, 
    "node_proxy_tcp": 37650, 
    "deno_proxy_tcp": 27001, 
    "hyper": 71043, 
    "node_tcp": 78366, 
    "deno_http": 24931, 
    "node_http": 34228, 
    "node_proxy": 4364
  }, 
  "max_latency": {
    "deno_tcp": 2.4, 
    "deno_core_http_bench": 1.24, 
    "node_proxy_tcp": 1.73, 
    "deno_proxy_tcp": 2.66, 
    "hyper": 0.554, 
    "node_tcp": 1.84, 
    "deno_http": 1.79, 
    "node_http": 2.4, 
    "node_proxy": 6.98
  }, 

@SyrupThinker
Copy link
Contributor Author

Also pretty wonky. Node and Hyper differ a lot between the runs :/
If we go by master and try one where the references values are close'ish it might be a small improvement. But I wouldn't read into that.

ry
ry previously requested changes Jun 11, 2020
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SyrupThinker We have concerns about the correctness of this patch in the way the control buffer gets rewritten on the shared buffer. I'm making this patch as "Request changes" so it doesn't accidentally get merged.

I suspect we can come up with a test case that introduces errors: modify the control buf during an async op, while there are other async ops happening.

@ry
Copy link
Member

ry commented Jun 23, 2020

From Discord chat:

@SyrupThinker: Could you show me where the SharedQueue is used for the control buffer? Because this PR suggests it has been removed. #2732 I couldn't find something immediately apparent in the log that readded it and the only usecase I can find is for the return value of Async ops

@ry: I'm looking and also not seeing it. It looks like the shared queue only is used for response buffers. Which a vaguely remember now as being the case. Ok - so your patch might indeed be okay.

@ry
Copy link
Member

ry commented Jun 23, 2020

@SyrupThinker Can you please merge with master? Note there's been a recent patch that introduced the dispatchByName() . It might require a bit of work. See #6395.

@SyrupThinker
Copy link
Contributor Author

What's the status on this?

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as "request changes" because in the current state this PR introduces panics when Deno.core.dispatch() is called without at least two arguments

v1.1.3

$ deno
Deno 1.1.3
exit using ctrl+d or close()
> const a = Deno.core.dispatch(10)
undefined
> new TextDecoder().decode(a)
{"err":{"message":"EOF while parsing a value at line 1 column 0","kind":17},"promiseId":null}

this PR

target/debug/deno
Deno 1.1.2
exit using ctrl+d or close()
> const a = Deno.core.dispatch(10)
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', cli/state.rs:107:32
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
[1]    21816 abort      target/debug/deno

@SyrupThinker I think there should be some validation added in core/bindings.rs::send that there's at least one zero copy buffer passed or some JS error returned informing that too few arguments were passed.

@SyrupThinker
Copy link
Contributor Author

I think there should be some validation added in core/bindings.rs::send that there's at least one zero copy buffer passed or some JS error returned informing that too few arguments were passed.

That seems like an arbitrary restriction to me. If my op just changes the system state and doesn't take parameters why should I be forced to pass an argument anyway?
The plugin API could add support for defining arity of a function, but I'm not sure how helpful that is considering that normal user should never call ops directly.

@ry
Copy link
Member

ry commented Jul 8, 2020

@SyrupThinker I apologize for the delay in landing this patch. It's a very central change so we have to be careful.

I will land this today. I want to see its effects on the benchmarks. Potentially it will be reverted if we see some negative side effects. Potentially we'll just land some fixes for the issue Bartek brought up.

Bartek, it's a good point but let's just land this anyway. Deno.core.dispatch has an ambiguous stability status anyway (it's not included in deno types but it is included in the runtime).

Just waiting for the last few commits I landed to go green. Then I will merge this.

@ry ry dismissed bartlomieju’s stale review July 8, 2020 15:07

we can do this later

@SyrupThinker
Copy link
Contributor Author

land some fixes for the issue Bartek brought up

Thats what the last commit did ;)

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thank you for all the hard work @SyrupThinker

@ry ry merged commit be7e0f2 into denoland:master Jul 8, 2020
@SyrupThinker SyrupThinker deleted the remove_control_slice branch July 13, 2020 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir deno_core Changes in "deno_core" crate are needed perf performance related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants