最新消息 async await 已被 node.js 正式支持,不需要 --harmony 了
发布于 2 年前 作者 andyhu 3600 次浏览 来自 分享

另外 koa 2.0 即将发布,真是一个好消息!

19 回复

就等import了

来自 KoaHubjs

koa2.0已经在用了

来自 KoaHub.js

昨天安装还是7.5,现在就7.6了

赞,7.6终于支持async/await

这是最吼滴

牛逼 homebrew更新了一下 已经7.6了

真是好消息啊 也希望原生的Promise能更优化一点,提供更多的方法。

@einsqing 估计楼主的意思是2.x正式版的意思 koa团队一直在等待node对async的默认支持

@zengming00 我也是昨天安装还是7。5

import 有提案了?

Async functions

In 5.5, V8 ships JavaScript ES2017 async functions, which makes it easier to write code that uses and creates Promises. Using async functions, waiting for a Promise to resolve is as simple as typing await before it and proceeding as if the value were synchronously available - no callbacks required. See this article for an introduction.

Here’s an example function which fetches a URL and returns the text of the response, written in a typical asynchronous, Promise-based style.

function logFetch(url) {
  return fetch(url)
    .then(response => response.text())
    .then(text => {
      console.log(text);
    }).catch(err => {
      console.error('fetch failed', err);
    });
}

Here’s the same code rewritten to remove callbacks, using async functions.

async function logFetch(url) {
  try {
    const response = await fetch(url);
    console.log(await response.text());
  } catch (err) {
    console.log('fetch failed', err);
  }
}

Performance improvements

V8 5.5 delivers a number of key improvements in memory footprint.

Memory

Memory consumption is an important dimension in the JavaScript virtual machine performance trade-off space. Over the last few releases, the V8 team analyzed and significantly reduced the memory footprint of several websites that were identified as representative of modern web development patterns. V8 5.5 reduces Chrome’s overall memory consumption by up to 35% on low-memory devices (compared to V8 5.3 in Chrome 53) due to reductions in the V8 heap size and zone memory usage. Other device segments also benefit from the zone memory reductions. Please have a look at the dedicated blog post to get a detailed view.

谁有时间翻译一下这段?

真是一个好消息!

koa 2.0 也没个发布计划时间表。

然而v8已经撸到5.7了, 总算async/await 能有个4倍左右的提升, 之前的本地测试 Node 7.4的koa2 async/await 比 express还稍差一点(10~25中间件),希望等用上5.7后能赶上koa1吧

https://v8project.blogspot.sg/2017/02/v8-release-57.html

v8 5.5 实现了内存占用的一些关键优化 内存占用高是JS虚拟机实现高性能的一个重要取舍。在之前几个版本中,V8团队分析并显著降低了一些应用现代web开发模式的代表性网站的内存占用。v8 5.5版 通过降低heap size 和zone memory usage,降低了chrome在低内存设备至多35%的总体内存消耗(和chrome 53的v8 5.3相比)。其他设备也能从更低的zone memory usage获益

这俩名词想不出合适的翻译。。慢慢啃原文吧 heap size & zone memory usage 是啥 v8 heap size

@w10036w 我测试的koa稍高一点点,偶尔比express低的

@i5ting 下午测试了下7.6.0 t8 c50 mw10/15/20/25,koa2 async 达到koa2的2/3,已经超越express和koa1 主要考虑到实际使用中边缘情况较少,所以没算<10和>30的情况 koa2 async/await

Running 3s test @ http://localhost:3333
  8 threads and 50 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     5.25ms    1.88ms  35.58ms   95.94%
    Req/Sec     1.17k   186.09     1.32k    93.55%
  28941 requests in 3.10s, 4.17MB read
Requests/sec:   9321.19
Transfer/sec:      1.34MB

koa2

Running 3s test @ http://localhost:3333
  8 threads and 50 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.61ms    1.60ms  34.12ms   95.88%
    Req/Sec     1.72k   271.24     1.90k    93.55%
  42541 requests in 3.10s, 6.13MB read
Requests/sec:  13711.05
Transfer/sec:      1.97MB

koa1

Running 3s test @ http://localhost:3333
  8 threads and 50 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     5.36ms    1.67ms  34.49ms   93.26%
    Req/Sec     1.14k   242.39     2.91k    95.47%
  27602 requests in 3.10s, 3.97MB read
Requests/sec:   8897.56
Transfer/sec:      1.28MB

express

Running 3s test @ http://localhost:3333
  8 threads and 50 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     6.10ms    1.91ms  37.10ms   91.94%
    Req/Sec     1.00k   181.97     1.81k    91.43%
  24442 requests in 3.10s, 4.90MB read
Requests/sec:   7874.38
Transfer/sec:      1.58MB

@w10036w请教大神,怎么测试的?

回到顶部