{"id":319242,"date":"2021-03-09T09:01:11","date_gmt":"2021-03-09T09:01:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=319242"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=319242","title":{"rendered":"\u0420\u0430\u0437\u0433\u043e\u043d\u044f\u0435\u043c JS-\u043f\u0430\u0440\u0441\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e WebAssembly (\u0447\u0430\u0441\u0442\u044c 1: \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438)"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/post\/534340\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u044f\u0441\u043d\u0435\u043d\u0438\u044e \u043f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u044f \u0432 \u0441\u043e\u0441\u0442\u044f\u0437\u0430\u043d\u0438\u0438 JS-\u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/REL_12_STABLE\/src\/backend\/commands\/explain.c#L2871\">\u0441\u0442\u0440\u043e\u043a\u0438 buffers-\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430<\/a>&nbsp;\u0443\u0437\u043b\u0430 \u043f\u043b\u0430\u043d\u0430 PostgreSQL, \u043c\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u0444\u0430\u043a\u0442\u0430, \u0447\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 &#8212; \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442<\/strong> \u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u043b\u044e\u0431\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0434 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 <code>.charCodeAt<\/code>, \u0435\u0441\u043b\u0438 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u0438\u0434\u0430&nbsp;<code>'Buffers: shared hit=123 read=456, local hit=789'<\/code>&nbsp;\u043c\u044b \u0445\u043e\u0442\u0438\u043c <strong>\u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435<\/strong> \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c JSON \u0444\u043e\u0440\u043c\u0430\u0442\u0430:<\/p>\n<pre><code class=\"json\">{   \"shared-hit\"  : 123 , \"shared-read\" : 456 , \"local-hit\"   : 789 }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c <a href=\"https:\/\/gist.githubusercontent.com\/Kilor\/8c4fee60a94073c1accc6bdd167e9990\/raw\/8b2918e5eb55c1e61034e80adb10554551434718\/buffers.txt\">\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435<\/a> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0440\u044f\u0434\u043a\u0430 <strong>48ms<\/strong> \u043d\u0430 6.3MB \u0438\u043b\u0438 \u043e\u043a\u043e\u043b\u043e 130MB\/s, \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 11 \u0440\u0430\u0437 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043d\u0430\u0438\u0432\u043d\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0441\u043e <code>.split<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>Hardcore State Machine<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"javascript\">const buffersKeys = ['shared-hit', 'shared-read', 'shared-dirtied', 'shared-written', 'local-hit', 'local-read', 'local-dirtied', 'local-written', 'temp-hit', 'temp-read', 'temp-dirtied', 'temp-written'];  const parseBuffers = line =&gt; {   let rv = {};    let state;   let key;    _word: for (let off = 9 \/*'Buffers: '*\/, ln = line.length; off &lt; ln; ) {     switch (line.charCodeAt(off)) {       case 0x73: \/\/ s = shared         state = 0;         off += 7;         continue _word;       case 0x6c: \/\/ l = local         state = 4;         off += 6;         continue _word;       case 0x74: \/\/ t = temp         state = 8;         off += 5;         continue _word;        case 0x68: \/\/ h = hit         key = state;         off += 4;         break;       case 0x72: \/\/ r = read         key = state + 1;         off += 5;         break;       case 0x64: \/\/ d = dirtied         key = state + 2;         off += 8;         break;       case 0x77: \/\/ w = written         key = state + 3;         off += 8;         break;     }      let val = 0;     _digit: for (; off &lt; ln; off++) {       let ch = line.charCodeAt(off);       switch (ch) {         case 0x20: \/\/ ' '           off++;           break _digit;         case 0x2c: \/\/ ','           off += 2;           break _digit;         default:           val = val * 10 + ch - 0x30; \/\/ '0'       }     }      rv[buffersKeys[key]] = val;   }   return rv; }; <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441: &#171;\u0410 \u0435\u0449\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 &#8212; \u043c\u043e\u0436\u043d\u043e?&#187;<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/540\/056\/4a7\/5400564a79cbe4316d359e23ff9dca2b.png\" width=\"2445\" height=\"990\"><figcaption><\/figcaption><\/figure>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u044c\u0441\u044f \u043a \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c &#171;\u0436\u0435\u043b\u0435\u0437\u0430&#187;, \u043d\u043e \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0432 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 JavaScript, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u0440\u0435\u0448\u0430\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/WebAssembly\">WebAssembly<\/a>, \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0432\u0448\u0438\u0441\u044c \u043f\u043e \u043f\u0443\u0442\u0438 \u0441\u043f\u043e\u0442\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u043e\u0431\u043e \u0432\u0441\u0435 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438.<\/p>\n<h2>\u0413\u043e\u0442\u043e\u0432\u0438\u043c \u0442\u0440\u0430\u043c\u043f\u043b\u0438\u043d<\/h2>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u0437 \u043a\u043e\u0434\u0430 HSM-\u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0443\u0436\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0445\u0430\u0440\u0434\u043a\u043e\u0440 \u043c\u044b \u043b\u044e\u0431\u0438\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0432 \u0442\u043e\u043c \u0436\u0435 \u0434\u0443\u0445\u0435 &#8212; \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u043c \u0432\u0440\u0443\u0447\u043d\u0443\u044e, <strong>\u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/strong> <a href=\"https:\/\/ru.wikipedia.org\/wiki\/Emscripten\">Emscripten<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f <a href=\"https:\/\/github.com\/WebAssembly\/wabt\">\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 WAT-\u0444\u0430\u0439\u043b\u043e\u0432<\/a> (WebAssembly Text Format):<\/p>\n<pre><code>npm install wabt<\/code><\/pre>\n<p>\u0418, \u043f\u0440\u044f\u043c\u043e \u043f\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c, \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u0438\u0437 \u043d\u0435\u0433\u043e \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 &#171;\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440&#187; <code>compile-test.js<\/code>:<\/p>\n<pre><code class=\"javascript\">const { readFileSync, writeFileSync } = require('fs');  const fn = 'buffers-test';  require('wabt')().then(wabt =&gt; {   const inputWat = `${fn}.wat`;   const outputWasm = `${fn}.wasm`;    const wasmModule = wabt.parseWat(inputWat, readFileSync(inputWat, 'utf8'));   const { buffer } = wasmModule.toBinary({});    writeFileSync(outputWasm, Buffer.from(buffer)); }); <\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043e\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 <code>buffers-test.wasm<\/code> \u0438\u0437 <code>buffers-test.wat<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043a\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0443 \u043d\u0430\u0441 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u043e\u0439 \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u043e\u0439:<\/p>\n<pre><code class=\"javascript\">(module   (func (result i32)     (i32.const 42)   )   (export \"helloWorld\" (func 0)) )<\/code><\/pre>\n<blockquote>\n<p>\u0414\u043b\u044f \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f <em>&#171;\u0447\u0442\u043e \u044d\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u0442\u0430\u043a\u043e\u0435?&#187;<\/em> \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0443\u0442 \u0441\u0442\u0430\u0442\u044c\u044f \u0438\u0437 MDN <a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/WebAssembly\/Understanding_the_text_format\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 WebAssembly<\/a> \u0438 \u043f\u043e\u043b\u043d\u044b\u0439 <a href=\"https:\/\/webassembly.github.io\/spec\/core\/syntax\/instructions.html\">\u043f\u0435\u0440\u0435\u0447\u0435\u043d\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 WASM-\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439<\/a>.<\/p>\n<\/blockquote>\n<p>\u0410 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0437 <code>buffers-test.js<\/code>:<\/p>\n<pre><code class=\"javascript\">const { readFileSync } = require('fs');  const fn = 'buffers-test';  const run = async () =&gt; {   const buffer = readFileSync(`${fn}.wasm`);   const module = await WebAssembly.compile(buffer);      const instance = await WebAssembly.instantiate(module);   console.log(instance.exports.helloWorld()); };  run();<\/code><\/pre>\n<h2>\u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0438\u0437 WASM \u0432 JS<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0440\u0430\u0431\u043e\u0442\u044b WASM-\u043a\u043e\u0434\u0430 &#8212; \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041d\u043e \u043e\u043d \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 &#8212; \u0438 \u0440\u0430\u0437 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u043d\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0438\u0445 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c.<\/p>\n<h4>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h4>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448 \u043a\u043e\u0434 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u043d\u043e\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0440\u0430\u0437:<\/p>\n<pre><code class=\"javascript\">\/\/ ...     const hw = instance.exports.helloWorld;    const hrb = process.hrtime();   \/\/ -- 8&lt; --   for (let i = 1; i &lt; 1000000; i++) {     let v = hw(); \/\/ \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430   }   \/\/ -- 8&lt; --   const hre = process.hrtime(hrb);   const usec = hre[0] * 1e+9 + hre[1];   console.log(usec); \/\/ ...<\/code><\/pre>\n<pre><code class=\"javascript\">(module   ;; \u044d\u0442\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0443\u043b\u044f, \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438\u043c\u0435\u044e\u0442 \u0432\u0441\u0435 \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438   ;; let val = 0 - \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0435, \u043d\u0435-const, \u0446\u0435\u043b\u043e\u0435 32-bit \u0447\u0438\u0441\u043b\u043e   (global $val (mut i32)     (i32.const 0)   )    (func (export \"helloWorld\") (result i32) ;; \u0441\u0440\u0430\u0437\u0443 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0441 \u043d\u0443\u0436\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c     ;; val++ - \u0434\u0430, \u0432\u043e\u0442 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u043e     (global.set $val       (i32.add         (global.get $val)         (i32.const 1)       )     )     ;; return val     (global.get $val)   ) )<\/code><\/pre>\n<p>\u0414\u043b\u044f NodeJS 15.9.0, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b, \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <strong>\u043e\u0442 10\u043c\u0441<\/strong> &#8212; \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 CPU.<\/p>\n<h4>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f<\/h4>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/WebAssembly\/Global\">\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 JS \u0432 WASM-\u043a\u043e\u0434, \u0442\u0430\u043a \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u0445 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<pre><code class=\"javascript\">\/\/ ...   \/\/ \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f WASM-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c 0   let val = new WebAssembly.Global({value : 'i32', mutable : true}, 0);   \/\/ \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \"\u0432\u043d\u0443\u0442\u0440\u044c\" WASM   const importObject = {     js : {       val     }   };   const instance = await WebAssembly.instantiate(module, importObject); \/\/ ...   for (let i = 1; i &lt; 1000000; i++) {     hw();     let v = val.value; \/\/ .value \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 WebAssembly.Global   }<\/code><\/pre>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0436\u0435 \u0432 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u043e\u043c \u043a\u043e\u0434\u0435 &#8212; \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435:<\/p>\n<pre><code class=\"javascript\">(module   ;; \u044d\u0442\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0438\u0437 JS-\u043a\u043e\u0434\u0430 \u043a\u0430\u043a importObject.js.val   (global $val (import \"js\" \"val\") (mut i32))    (func (export \"helloWorld\") ;; \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442     (global.set $val       (i32.add         (global.get $val)         (i32.const 1)       )     )   ) )<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435&#8230; \u043d\u043e \u0443\u0436\u0435 <strong>\u0437\u0430 48ms<\/strong>. \u041f\u043e\u0447\u0442\u0438 \u0432 5 \u0440\u0430\u0437 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u043e\u0434\u043d\u0430\u043a\u043e!<\/p>\n<p>\u0417\u0430\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u043c\u0435\u0441\u0442\u043e <code>val.value<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>val.valueOf()<\/code>, \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u0435\u0442 \u0438 \u0432\u043e\u0432\u0441\u0435 <strong>\u0434\u043e 58ms<\/strong>.<\/p>\n<h4>\u0420\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c<\/h4>\n<p>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043e\u0432\u0441\u0435\u043c \u0433\u0440\u0443\u0441\u0442\u043d\u043e, \u0432\u0435\u0434\u044c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041d\u043e \u043e\u0442\u0447\u0430\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u043d\u043e &#8212; \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0434\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/WebAssembly\/Memory\">\u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438<\/a>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u043e\u0431\u0449\u0435\u0435 \u0430\u0434\u0440\u0435\u0441\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043c\u0435\u0436\u0434\u0443 JS \u0438 WASM:<\/p>\n<pre><code class=\"javascript\">\/\/ ...   \/\/ \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0432 1 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443   const memory = new WebAssembly.Memory({initial : 1});   \/\/ \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 32-bit-\u0447\u0438\u0441\u0435\u043b   const prj32 = new Uint32Array(memory.buffer);    const importObject = {     js : {       memory     }   }; \/\/ ...   for (let i = 1; i &lt; 1000000; i++) {     hw();     let v = prj32[0]; \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438   } \/\/ ...<\/code><\/pre>\n<pre><code class=\"javascript\">(module   ;; \u044d\u0442\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0432 \u043e\u0434\u043d\u0443 64KB-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 importObject.js.memory   (import \"js\" \"memory\" (memory 1))    (func (export \"helloWorld\")     ;; memory[0] = memory[0] + 1     (i32.store       (i32.const 0) ;; offset       (i32.add      ;; data         (i32.load           (i32.const 0) ;; offset         )         (i32.const 1)       )     )   ) )<\/code><\/pre>\n<p>\u0418 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0443\u0436\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u0434\u043e\u0441\u0442\u043e\u0439\u043d\u044b\u0439 &#8212; <strong>\u043e\u0442 12ms<\/strong>. \u0422\u043e \u0435\u0441\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0437\u0430\u0442\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 &#8212; \u043d\u0430\u0434\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 JS \u0438 WASM-\u043a\u043e\u0434\u043e\u043c.<\/p>\n<blockquote>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <strong>WASM \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 &#171;\u0432 \u0431\u0430\u0439\u0442\u0430\u0445&#187;, \u0430 JS &#8212; &#171;\u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445&#187;<\/strong>.  \u0422\u043e \u0435\u0441\u0442\u044c \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <code>prj32[2]<\/code>, \u0442\u043e \u043f\u0438\u0441\u0430\u0442\u044c <code>i32.store<\/code> \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044e <code>8 = 2 * 4<\/code> (&#171;\u0431\u0430\u0439\u0442\u043e\u0432\u044b\u0439&#187; \u0440\u0430\u0437\u043c\u0435\u0440 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a <code>prj32.BYTES_PER_ELEMENT<\/code>).<\/p>\n<\/blockquote>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0438\u0447\u0442\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0438\u043c\u0435\u0442\u044c <strong>\u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e &#171;\u0440\u0430\u0437\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445&#187; \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439<\/strong> \u043d\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043d\u0435 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435, \u0430 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0441\u0430\u0439\u0434\u0435 \u0432 <strong>Node.js<\/strong>-\u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 &#8212; \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437 <a href=\"https:\/\/nodejs.org\/dist\/latest-v15.x\/docs\/api\/buffer.html\">Buffer<\/a>-\u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ ...   const buf = Buffer.from(memory.buffer); \/\/ \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 1-\u0431\u0430\u0439\u0442\u043e\u0432\u0430\u044f \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f \/\/ ...   for (let i = 1; i &lt; 1000000; i++) {     hw();     let v = buf.readUInt32LE(0); \/\/ \u0442\u0443\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u043e\u0436\u0435 \u043f\u043e\u0431\u0430\u0439\u0442\u043e\u0432\u043e\u0435   } \/\/ ...<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0430\u043c\u0438 \u043d\u0443\u0436\u043d\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438, \u043d\u043e <strong>\u043f\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u043c\u0443 \u0431\u0430\u0439\u0442\u043e\u0432\u043e\u043c\u0443 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044e<\/strong>, \u0431\u0435\u0437 \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u043e <code>BYTES_PER_ELEMENT<\/code>. \u0423\u0432\u044b, \u0437\u0430 \u0432\u0441\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043b\u0430\u0442\u0438\u0442\u044c &#8212; \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u0445\u0443\u0436\u0435 &#8212; <strong>16ms<\/strong>.<\/p>\n<h4>\u0412\u044b\u0437\u043e\u0432 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 WASM<\/h4>\n<p>\u0422\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0440\u0435\u0437\u043e\u043d\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441: \u0435\u0441\u043b\u0438 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043f\u043e\u0442\u0435\u0440\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u0437\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u0437 JS \u0432 WASM &#8212; \u0442\u0430\u043a \u043d\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0438\u0437 WASM-\u043a\u043e\u0434\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043d\u0443\u0436\u043d\u043e\u0439 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0438?<\/p>\n<pre><code class=\"javascript\">\/\/ ...   const func = v =&gt; {     \/\/ \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 WASM     \/\/ console.log(v)   };    const importObject = {     js : {       memory     , func     }   }; \/\/ ...   for (let i = 1; i &lt; 1000000; i++) {     hw();   } \/\/ ...<\/code><\/pre>\n<pre><code class=\"javascript\">(module   ;; \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0438\u043c\u044f \u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0438   (import \"js\" \"func\" (func $js_func (param i32)))   (import \"js\" \"memory\" (memory 1))    (func (export \"helloWorld\")     ;; memory[0] = memory[0] + 1     (i32.store       (i32.const 0)       (i32.add         (i32.load           (i32.const 0)         )         (i32.const 1)       )     )     ;; \u0432\u044b\u0437\u043e\u0432 js.func(memory[0])     (call $js_func       (i32.load         (i32.const 0)       )     )   ) )<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0435\u0449\u0435 \u0447\u0443\u0442\u044c \u0445\u0443\u0436\u0435 &#8212; \u043f\u043e\u0440\u044f\u0434\u043a\u0430 <strong>20ms<\/strong>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f\/\u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0435\u043a\u0430 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041f\u043e\u0434\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u0438\u0442\u043e\u0433\u0438:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\" data-colwidth=\"461,0\" width=\"461\">\n<p><strong>\u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<\/td>\n<td>\n<p><strong>10ms<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f .value<\/p>\n<\/td>\n<td>\n<p>48ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f .valueOf()<\/p>\n<\/td>\n<td>\n<p>58ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0412\u044b\u0437\u043e\u0432 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<\/td>\n<td>\n<p>20ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" data-colwidth=\"461,0\" width=\"461\">\n<p><strong>\u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u043d\u0430\u0431\u043e\u0440\u0430<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0420\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 ArrayBuffer<\/p>\n<\/td>\n<td>\n<p><strong>12ms<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0420\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 Buffer<\/p>\n<\/td>\n<td>\n<p>16ms<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>BigInt vs \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 32bit-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u043e \u0441\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u0432\u044b\u0445\u043e\u0434\u044f\u0449\u0438\u043c\u0438 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u044d\u0442\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f <code>BigInt<\/code> \u0438\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u043f\u0430\u0440\u044b 32bit-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"658\" width=\"658\">\n<p><code>const buf = Buffer.from(memory.buffer);<\/code><\/p>\n<p><code>let v = buf.readBigUInt64LE(0);<\/code><\/p>\n<\/td>\n<td>\n<p>136ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"658\" width=\"658\">\n<p><code>const prj64 = new BigUint64Array(memory.buffer);<\/code><\/p>\n<p><code>let v = prj64[0];<\/code><\/p>\n<\/td>\n<td>\n<p>24ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"658\" width=\"658\">\n<p><code>const prj32 = new Uint32Array(memory.buffer);<\/code><\/p>\n<p><code>let v = prj32[0] + prj32[1] * 0x100000000;<\/code><\/p>\n<\/td>\n<td>\n<p><strong>14ms<\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c, \u0432\u044b\u0431\u043e\u0440 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u0435\u043d &#8212; \u043f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 <strong>\u0441\u0442\u043e\u0438\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f 32bit-\u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0435\u0439<\/strong>.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 JS \u0432 WASM<\/h2>\n<p>\u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c \u0432 WASM-\u043a\u043e\u0434\u0435 \u0441\u0440\u0430\u0437\u0443 \u0432\u0435\u0441\u044c \u0444\u0430\u0439\u043b, \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0434 \u043e\u0431\u043c\u0435\u043d \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ ...   const prj32 = new Uint32Array(memory.buffer); \/\/ 4-\u0431\u0430\u0439\u0442\u043e\u0432\u0430\u044f \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f   const prj8 = new Uint8Array(memory.buffer);   \/\/ 1-\u0431\u0430\u0439\u0442\u043e\u0432\u0430\u044f \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f    const offset = 1 &lt;&lt; 16; \/\/ \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0435\u0440\u0432\u043e\u0439 64KB-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b    const data = readFileSync('buffers.txt');   \/\/ _\u043d\u0430_ \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c   memory.grow((data.byteLength &gt;&gt; 16) + 1);    \/\/ \u0437\u0430\u043b\u0438\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e 2-\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b   data.copy(prj8, offset); \/\/ ...<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043d\u043e \u043d\u0435\u0434\u043e\u043b\u0433\u043e \u0438 \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>memory.grow<\/code> \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u0443\u0436\u0435 \u043d\u043e\u0432\u044b\u0439 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u043f\u0430\u043c\u044f\u0442\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 <strong>\u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u043d\u0430\u0434\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u043d\u0430\u0440\u0430\u0449\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438<\/strong>:<\/p>\n<pre><code class=\"javascript\">\/\/ ...   memory.grow((data.byteLength &gt;&gt; 16) + 1);   const prj32 = new Uint32Array(memory.buffer);   const prj8 = new Uint8Array(memory.buffer); \/\/ ...<\/code><\/pre>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<hr>\n<p>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/WebAssembly\/wabt\">WABT: The WebAssembly Binary Toolkit<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/WebAssembly\/Understanding_the_text_format\">MDN: \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 WebAssembly<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/webassembly.github.io\/spec\/core\/syntax\/instructions.html\">WebAssembly: Instructions<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/WebAssembly\/Global\">MDN: WebAssembly.Global<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/WebAssembly\/Memory\">MDN: WebAssembly.Memory<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/tensor\/blog\/544824\/\"> https:\/\/habr.com\/ru\/company\/tensor\/blog\/544824\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/post\/534340\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u044f\u0441\u043d\u0435\u043d\u0438\u044e \u043f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u044f \u0432 \u0441\u043e\u0441\u0442\u044f\u0437\u0430\u043d\u0438\u0438 JS-\u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/REL_12_STABLE\/src\/backend\/commands\/explain.c#L2871\">\u0441\u0442\u0440\u043e\u043a\u0438 buffers-\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430<\/a>&nbsp;\u0443\u0437\u043b\u0430 \u043f\u043b\u0430\u043d\u0430 PostgreSQL, \u043c\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u0444\u0430\u043a\u0442\u0430, \u0447\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 &#8212; \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442<\/strong> \u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u043b\u044e\u0431\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0434 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 <code>.charCodeAt<\/code>, \u0435\u0441\u043b\u0438 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u0438\u0434\u0430&nbsp;<code>'Buffers: shared hit=123 read=456, local hit=789'<\/code>&nbsp;\u043c\u044b \u0445\u043e\u0442\u0438\u043c <strong>\u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435<\/strong> \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c JSON \u0444\u043e\u0440\u043c\u0430\u0442\u0430:<\/p>\n<pre><code class=\"json\">{   \"shared-hit\"  : 123 , \"shared-read\" : 456 , \"local-hit\"   : 789 }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c <a href=\"https:\/\/gist.githubusercontent.com\/Kilor\/8c4fee60a94073c1accc6bdd167e9990\/raw\/8b2918e5eb55c1e61034e80adb10554551434718\/buffers.txt\">\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435<\/a> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0440\u044f\u0434\u043a\u0430 <strong>48ms<\/strong> \u043d\u0430 6.3MB \u0438\u043b\u0438 \u043e\u043a\u043e\u043b\u043e 130MB\/s, \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 11 \u0440\u0430\u0437 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043d\u0430\u0438\u0432\u043d\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0441\u043e <code>.split<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>Hardcore State Machine<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"javascript\">const buffersKeys = ['shared-hit', 'shared-read', 'shared-dirtied', 'shared-written', 'local-hit', 'local-read', 'local-dirtied', 'local-written', 'temp-hit', 'temp-read', 'temp-dirtied', 'temp-written'];  const parseBuffers = line =&gt; {   let rv = {};    let state;   let key;    _word: for (let off = 9 \/*'Buffers: '*\/, ln = line.length; off &lt; ln; ) {     switch (line.charCodeAt(off)) {       case 0x73: \/\/ s = shared         state = 0;         off += 7;         continue _word;       case 0x6c: \/\/ l = local         state = 4;         off += 6;         continue _word;       case 0x74: \/\/ t = temp         state = 8;         off += 5;         continue _word;        case 0x68: \/\/ h = hit         key = state;         off += 4;         break;       case 0x72: \/\/ r = read         key = state + 1;         off += 5;         break;       case 0x64: \/\/ d = dirtied         key = state + 2;         off += 8;         break;       case 0x77: \/\/ w = written         key = state + 3;         off += 8;         break;     }      let val = 0;     _digit: for (; off &lt; ln; off++) {       let ch = line.charCodeAt(off);       switch (ch) {         case 0x20: \/\/ ' '           off++;           break _digit;         case 0x2c: \/\/ ','           off += 2;           break _digit;         default:           val = val * 10 + ch - 0x30; \/\/ '0'       }     }      rv[buffersKeys[key]] = val;   }   return rv; }; <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441: &#171;\u0410 \u0435\u0449\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 &#8212; \u043c\u043e\u0436\u043d\u043e?&#187;<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u044c\u0441\u044f \u043a \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c &#171;\u0436\u0435\u043b\u0435\u0437\u0430&#187;, \u043d\u043e \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0432 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 JavaScript, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u0440\u0435\u0448\u0430\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/WebAssembly\">WebAssembly<\/a>, \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0432\u0448\u0438\u0441\u044c \u043f\u043e \u043f\u0443\u0442\u0438 \u0441\u043f\u043e\u0442\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u043e\u0431\u043e \u0432\u0441\u0435 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438.<\/p>\n<h2>\u0413\u043e\u0442\u043e\u0432\u0438\u043c \u0442\u0440\u0430\u043c\u043f\u043b\u0438\u043d<\/h2>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u0437 \u043a\u043e\u0434\u0430 HSM-\u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0443\u0436\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0445\u0430\u0440\u0434\u043a\u043e\u0440 \u043c\u044b \u043b\u044e\u0431\u0438\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0432 \u0442\u043e\u043c \u0436\u0435 \u0434\u0443\u0445\u0435 &#8212; \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u043c \u0432\u0440\u0443\u0447\u043d\u0443\u044e, <strong>\u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/strong> <a href=\"https:\/\/ru.wikipedia.org\/wiki\/Emscripten\">Emscripten<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f <a href=\"https:\/\/github.com\/WebAssembly\/wabt\">\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 WAT-\u0444\u0430\u0439\u043b\u043e\u0432<\/a> (WebAssembly Text Format):<\/p>\n<pre><code>npm install wabt<\/code><\/pre>\n<p>\u0418, \u043f\u0440\u044f\u043c\u043e \u043f\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c, \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u0438\u0437 \u043d\u0435\u0433\u043e \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 &#171;\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440&#187; <code>compile-test.js<\/code>:<\/p>\n<pre><code class=\"javascript\">const { readFileSync, writeFileSync } = require('fs');  const fn = 'buffers-test';  require('wabt')().then(wabt =&gt; {   const inputWat = `${fn}.wat`;   const outputWasm = `${fn}.wasm`;    const wasmModule = wabt.parseWat(inputWat, readFileSync(inputWat, 'utf8'));   const { buffer } = wasmModule.toBinary({});    writeFileSync(outputWasm, Buffer.from(buffer)); }); <\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043e\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 <code>buffers-test.wasm<\/code> \u0438\u0437 <code>buffers-test.wat<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043a\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0443 \u043d\u0430\u0441 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u043e\u0439 \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u043e\u0439:<\/p>\n<pre><code class=\"javascript\">(module   (func (result i32)     (i32.const 42)   )   (export \"helloWorld\" (func 0)) )<\/code><\/pre>\n<blockquote>\n<p>\u0414\u043b\u044f \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f <em>&#171;\u0447\u0442\u043e \u044d\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u0442\u0430\u043a\u043e\u0435?&#187;<\/em> \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0443\u0442 \u0441\u0442\u0430\u0442\u044c\u044f \u0438\u0437 MDN <a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/WebAssembly\/Understanding_the_text_format\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 WebAssembly<\/a> \u0438 \u043f\u043e\u043b\u043d\u044b\u0439 <a href=\"https:\/\/webassembly.github.io\/spec\/core\/syntax\/instructions.html\">\u043f\u0435\u0440\u0435\u0447\u0435\u043d\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 WASM-\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439<\/a>.<\/p>\n<\/blockquote>\n<p>\u0410 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0437 <code>buffers-test.js<\/code>:<\/p>\n<pre><code class=\"javascript\">const { readFileSync } = require('fs');  const fn = 'buffers-test';  const run = async () =&gt; {   const buffer = readFileSync(`${fn}.wasm`);   const module = await WebAssembly.compile(buffer);      const instance = await WebAssembly.instantiate(module);   console.log(instance.exports.helloWorld()); };  run();<\/code><\/pre>\n<h2>\u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0438\u0437 WASM \u0432 JS<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0440\u0430\u0431\u043e\u0442\u044b WASM-\u043a\u043e\u0434\u0430 &#8212; \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041d\u043e \u043e\u043d \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 &#8212; \u0438 \u0440\u0430\u0437 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u043d\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0438\u0445 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c.<\/p>\n<h4>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h4>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448 \u043a\u043e\u0434 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u043d\u043e\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0440\u0430\u0437:<\/p>\n<pre><code class=\"javascript\">\/\/ ...     const hw = instance.exports.helloWorld;    const hrb = process.hrtime();   \/\/ -- 8&lt; --   for (let i = 1; i &lt; 1000000; i++) {     let v = hw(); \/\/ \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430   }   \/\/ -- 8&lt; --   const hre = process.hrtime(hrb);   const usec = hre[0] * 1e+9 + hre[1];   console.log(usec); \/\/ ...<\/code><\/pre>\n<pre><code class=\"javascript\">(module   ;; \u044d\u0442\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0443\u043b\u044f, \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438\u043c\u0435\u044e\u0442 \u0432\u0441\u0435 \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438   ;; let val = 0 - \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0435, \u043d\u0435-const, \u0446\u0435\u043b\u043e\u0435 32-bit \u0447\u0438\u0441\u043b\u043e   (global $val (mut i32)     (i32.const 0)   )    (func (export \"helloWorld\") (result i32) ;; \u0441\u0440\u0430\u0437\u0443 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0441 \u043d\u0443\u0436\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c     ;; val++ - \u0434\u0430, \u0432\u043e\u0442 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u043e     (global.set $val       (i32.add         (global.get $val)         (i32.const 1)       )     )     ;; return val     (global.get $val)   ) )<\/code><\/pre>\n<p>\u0414\u043b\u044f NodeJS 15.9.0, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b, \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <strong>\u043e\u0442 10\u043c\u0441<\/strong> &#8212; \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 CPU.<\/p>\n<h4>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f<\/h4>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/WebAssembly\/Global\">\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 JS \u0432 WASM-\u043a\u043e\u0434, \u0442\u0430\u043a \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u0445 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<pre><code class=\"javascript\">\/\/ ...   \/\/ \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f WASM-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c 0   let val = new WebAssembly.Global({value : 'i32', mutable : true}, 0);   \/\/ \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \"\u0432\u043d\u0443\u0442\u0440\u044c\" WASM   const importObject = {     js : {       val     }   };   const instance = await WebAssembly.instantiate(module, importObject); \/\/ ...   for (let i = 1; i &lt; 1000000; i++) {     hw();     let v = val.value; \/\/ .value \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 WebAssembly.Global   }<\/code><\/pre>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0436\u0435 \u0432 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u043e\u043c \u043a\u043e\u0434\u0435 &#8212; \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435:<\/p>\n<pre><code class=\"javascript\">(module   ;; \u044d\u0442\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0438\u0437 JS-\u043a\u043e\u0434\u0430 \u043a\u0430\u043a importObject.js.val   (global $val (import \"js\" \"val\") (mut i32))    (func (export \"helloWorld\") ;; \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442     (global.set $val       (i32.add         (global.get $val)         (i32.const 1)       )     )   ) )<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435&#8230; \u043d\u043e \u0443\u0436\u0435 <strong>\u0437\u0430 48ms<\/strong>. \u041f\u043e\u0447\u0442\u0438 \u0432 5 \u0440\u0430\u0437 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u043e\u0434\u043d\u0430\u043a\u043e!<\/p>\n<p>\u0417\u0430\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u043c\u0435\u0441\u0442\u043e <code>val.value<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>val.valueOf()<\/code>, \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u0435\u0442 \u0438 \u0432\u043e\u0432\u0441\u0435 <strong>\u0434\u043e 58ms<\/strong>.<\/p>\n<h4>\u0420\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c<\/h4>\n<p>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043e\u0432\u0441\u0435\u043c \u0433\u0440\u0443\u0441\u0442\u043d\u043e, \u0432\u0435\u0434\u044c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041d\u043e \u043e\u0442\u0447\u0430\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u043d\u043e &#8212; \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0434\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/WebAssembly\/Memory\">\u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438<\/a>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u043e\u0431\u0449\u0435\u0435 \u0430\u0434\u0440\u0435\u0441\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043c\u0435\u0436\u0434\u0443 JS \u0438 WASM:<\/p>\n<pre><code class=\"javascript\">\/\/ ...   \/\/ \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0432 1 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443   const memory = new WebAssembly.Memory({initial : 1});   \/\/ \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 32-bit-\u0447\u0438\u0441\u0435\u043b   const prj32 = new Uint32Array(memory.buffer);    const importObject = {     js : {       memory     }   }; \/\/ ...   for (let i = 1; i &lt; 1000000; i++) {     hw();     let v = prj32[0]; \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438   } \/\/ ...<\/code><\/pre>\n<pre><code class=\"javascript\">(module   ;; \u044d\u0442\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0432 \u043e\u0434\u043d\u0443 64KB-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 importObject.js.memory   (import \"js\" \"memory\" (memory 1))    (func (export \"helloWorld\")     ;; memory[0] = memory[0] + 1     (i32.store       (i32.const 0) ;; offset       (i32.add      ;; data         (i32.load           (i32.const 0) ;; offset         )         (i32.const 1)       )     )   ) )<\/code><\/pre>\n<p>\u0418 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0443\u0436\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u0434\u043e\u0441\u0442\u043e\u0439\u043d\u044b\u0439 &#8212; <strong>\u043e\u0442 12ms<\/strong>. \u0422\u043e \u0435\u0441\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0437\u0430\u0442\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 &#8212; \u043d\u0430\u0434\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 JS \u0438 WASM-\u043a\u043e\u0434\u043e\u043c.<\/p>\n<blockquote>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <strong>WASM \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 &#171;\u0432 \u0431\u0430\u0439\u0442\u0430\u0445&#187;, \u0430 JS &#8212; &#171;\u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445&#187;<\/strong>.  \u0422\u043e \u0435\u0441\u0442\u044c \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <code>prj32[2]<\/code>, \u0442\u043e \u043f\u0438\u0441\u0430\u0442\u044c <code>i32.store<\/code> \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044e <code>8 = 2 * 4<\/code> (&#171;\u0431\u0430\u0439\u0442\u043e\u0432\u044b\u0439&#187; \u0440\u0430\u0437\u043c\u0435\u0440 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a <code>prj32.BYTES_PER_ELEMENT<\/code>).<\/p>\n<\/blockquote>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0438\u0447\u0442\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0438\u043c\u0435\u0442\u044c <strong>\u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e &#171;\u0440\u0430\u0437\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445&#187; \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439<\/strong> \u043d\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043d\u0435 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435, \u0430 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0441\u0430\u0439\u0434\u0435 \u0432 <strong>Node.js<\/strong>-\u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 &#8212; \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437 <a href=\"https:\/\/nodejs.org\/dist\/latest-v15.x\/docs\/api\/buffer.html\">Buffer<\/a>-\u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ ...   const buf = Buffer.from(memory.buffer); \/\/ \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 1-\u0431\u0430\u0439\u0442\u043e\u0432\u0430\u044f \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f \/\/ ...   for (let i = 1; i &lt; 1000000; i++) {     hw();     let v = buf.readUInt32LE(0); \/\/ \u0442\u0443\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u043e\u0436\u0435 \u043f\u043e\u0431\u0430\u0439\u0442\u043e\u0432\u043e\u0435   } \/\/ ...<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0430\u043c\u0438 \u043d\u0443\u0436\u043d\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438, \u043d\u043e <strong>\u043f\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u043c\u0443 \u0431\u0430\u0439\u0442\u043e\u0432\u043e\u043c\u0443 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044e<\/strong>, \u0431\u0435\u0437 \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u043e <code>BYTES_PER_ELEMENT<\/code>. \u0423\u0432\u044b, \u0437\u0430 \u0432\u0441\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043b\u0430\u0442\u0438\u0442\u044c &#8212; \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u0445\u0443\u0436\u0435 &#8212; <strong>16ms<\/strong>.<\/p>\n<h4>\u0412\u044b\u0437\u043e\u0432 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 WASM<\/h4>\n<p>\u0422\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0440\u0435\u0437\u043e\u043d\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441: \u0435\u0441\u043b\u0438 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043f\u043e\u0442\u0435\u0440\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u0437\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u0437 JS \u0432 WASM &#8212; \u0442\u0430\u043a \u043d\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0438\u0437 WASM-\u043a\u043e\u0434\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043d\u0443\u0436\u043d\u043e\u0439 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0438?<\/p>\n<pre><code class=\"javascript\">\/\/ ...   const func = v =&gt; {     \/\/ \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 WASM     \/\/ console.log(v)   };    const importObject = {     js : {       memory     , func     }   }; \/\/ ...   for (let i = 1; i &lt; 1000000; i++) {     hw();   } \/\/ ...<\/code><\/pre>\n<pre><code class=\"javascript\">(module   ;; \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0438\u043c\u044f \u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0438   (import \"js\" \"func\" (func $js_func (param i32)))   (import \"js\" \"memory\" (memory 1))    (func (export \"helloWorld\")     ;; memory[0] = memory[0] + 1     (i32.store       (i32.const 0)       (i32.add         (i32.load           (i32.const 0)         )         (i32.const 1)       )     )     ;; \u0432\u044b\u0437\u043e\u0432 js.func(memory[0])     (call $js_func       (i32.load         (i32.const 0)       )     )   ) )<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0435\u0449\u0435 \u0447\u0443\u0442\u044c \u0445\u0443\u0436\u0435 &#8212; \u043f\u043e\u0440\u044f\u0434\u043a\u0430 <strong>20ms<\/strong>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f\/\u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0435\u043a\u0430 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041f\u043e\u0434\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u0438\u0442\u043e\u0433\u0438:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\" data-colwidth=\"461,0\" width=\"461\">\n<p><strong>\u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<\/td>\n<td>\n<p><strong>10ms<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f .value<\/p>\n<\/td>\n<td>\n<p>48ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f .valueOf()<\/p>\n<\/td>\n<td>\n<p>58ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0412\u044b\u0437\u043e\u0432 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<\/td>\n<td>\n<p>20ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" data-colwidth=\"461,0\" width=\"461\">\n<p><strong>\u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u043d\u0430\u0431\u043e\u0440\u0430<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0420\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 ArrayBuffer<\/p>\n<\/td>\n<td>\n<p><strong>12ms<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"461\" width=\"461\">\n<p>\u0420\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 Buffer<\/p>\n<\/td>\n<td>\n<p>16ms<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>BigInt vs \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041f\u043e\u043a\u0430<\/p>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-319242","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/319242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=319242"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/319242\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=319242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=319242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=319242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}