From 5129999be6b3af509c5056b432daefc73e09f92a Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Jun 2020 00:14:01 +0300 Subject: [PATCH 01/10] Use batching for fromCharCodes & fromCodePoints polyfills --- std/portable/index.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/std/portable/index.js b/std/portable/index.js index 80aeae3834..679bbd94e7 100644 --- a/std/portable/index.js +++ b/std/portable/index.js @@ -198,11 +198,38 @@ globalScope["changetype"] = function changetype(value) { }; String["fromCharCodes"] = function fromCharCodes(arr) { - return String.fromCharCode.apply(String, arr); + const CHUNKSIZE = 1 << 14; + const len = arr.length; + if (len <= CHUNKSIZE) { + return String.fromCodePoint.apply(String, arr); + } + let index = 0; + let parts = ''; + while (index < len) { + parts += String.fromCharCode.apply( + String, + arr.slice(index, Math.min(index + CHUNKSIZE, len)) + ); + index += CHUNKSIZE; + } + return parts; }; String["fromCodePoints"] = function fromCodePoints(arr) { - return String.fromCodePoint.apply(String, arr); + const CHUNKSIZE = 1 << 14; + let len = arr.length; + if (len <= CHUNKSIZE) { + return String.fromCharCode.apply(String, arr); + } + let index = 0; + let parts = ''; + do { + const last = arr[index + CHUNKSIZE - 1]; + const size = last >= 0xD800 && last < 0xDC00 ? CHUNKSIZE - 1 : CHUNKSIZE; + parts += String.fromCharCode.apply(String, arr.slice(index, index += size)); + len -= size; + } while (len > CHUNKSIZE); + return parts + String.fromCharCode.apply(String, arr.slice(index, index + len)); }; if (!String.prototype.replaceAll) { From fe49f8799eeba133ab4c4319f584b048b33a249f Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Jun 2020 00:43:16 +0300 Subject: [PATCH 02/10] reduce chunk size to 1 << 13 --- std/portable/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/std/portable/index.js b/std/portable/index.js index 679bbd94e7..698ea2ae69 100644 --- a/std/portable/index.js +++ b/std/portable/index.js @@ -198,7 +198,7 @@ globalScope["changetype"] = function changetype(value) { }; String["fromCharCodes"] = function fromCharCodes(arr) { - const CHUNKSIZE = 1 << 14; + const CHUNKSIZE = 1 << 13; const len = arr.length; if (len <= CHUNKSIZE) { return String.fromCodePoint.apply(String, arr); @@ -216,7 +216,7 @@ String["fromCharCodes"] = function fromCharCodes(arr) { }; String["fromCodePoints"] = function fromCodePoints(arr) { - const CHUNKSIZE = 1 << 14; + const CHUNKSIZE = 1 << 13; let len = arr.length; if (len <= CHUNKSIZE) { return String.fromCharCode.apply(String, arr); From 1b02f2ff3cc5e32b66675f8c537c24a3963e968e Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Jun 2020 00:53:17 +0300 Subject: [PATCH 03/10] fix --- std/portable/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/std/portable/index.js b/std/portable/index.js index 698ea2ae69..ad672fc0f6 100644 --- a/std/portable/index.js +++ b/std/portable/index.js @@ -201,7 +201,7 @@ String["fromCharCodes"] = function fromCharCodes(arr) { const CHUNKSIZE = 1 << 13; const len = arr.length; if (len <= CHUNKSIZE) { - return String.fromCodePoint.apply(String, arr); + return String.fromCharCode.apply(String, arr); } let index = 0; let parts = ''; @@ -219,7 +219,7 @@ String["fromCodePoints"] = function fromCodePoints(arr) { const CHUNKSIZE = 1 << 13; let len = arr.length; if (len <= CHUNKSIZE) { - return String.fromCharCode.apply(String, arr); + return String.fromCodePoints.apply(String, arr); } let index = 0; let parts = ''; From b3d9da5df67750038b243430dd23125cdd0a9d3d Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Jun 2020 01:03:42 +0300 Subject: [PATCH 04/10] what if 1 << 15 ? --- std/portable/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/std/portable/index.js b/std/portable/index.js index ad672fc0f6..5733907a01 100644 --- a/std/portable/index.js +++ b/std/portable/index.js @@ -198,7 +198,7 @@ globalScope["changetype"] = function changetype(value) { }; String["fromCharCodes"] = function fromCharCodes(arr) { - const CHUNKSIZE = 1 << 13; + const CHUNKSIZE = 1 << 15; const len = arr.length; if (len <= CHUNKSIZE) { return String.fromCharCode.apply(String, arr); @@ -216,7 +216,7 @@ String["fromCharCodes"] = function fromCharCodes(arr) { }; String["fromCodePoints"] = function fromCodePoints(arr) { - const CHUNKSIZE = 1 << 13; + const CHUNKSIZE = 1 << 15; let len = arr.length; if (len <= CHUNKSIZE) { return String.fromCodePoints.apply(String, arr); From 8ce29c0953a9c3cd1f14fc041f63898ae05e8d94 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Jun 2020 01:13:56 +0300 Subject: [PATCH 05/10] what if? --- std/portable/index.js | 64 +++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/std/portable/index.js b/std/portable/index.js index 5733907a01..f13bc6247a 100644 --- a/std/portable/index.js +++ b/std/portable/index.js @@ -198,38 +198,48 @@ globalScope["changetype"] = function changetype(value) { }; String["fromCharCodes"] = function fromCharCodes(arr) { - const CHUNKSIZE = 1 << 15; - const len = arr.length; - if (len <= CHUNKSIZE) { - return String.fromCharCode.apply(String, arr); + // const CHUNKSIZE = 1 << 15; + // const len = arr.length; + // if (len <= CHUNKSIZE) { + // return String.fromCharCode.apply(String, arr); + // } + // let index = 0; + // let parts = ''; + // while (index < len) { + // parts += String.fromCharCode.apply( + // String, + // arr.slice(index, Math.min(index + CHUNKSIZE, len)) + // ); + // index += CHUNKSIZE; + // } + // return parts; + let str = ''; + for (let i = 0, l = arr.length; i < l; i++) { + str += String.fromCharCode(arr[i]); } - let index = 0; - let parts = ''; - while (index < len) { - parts += String.fromCharCode.apply( - String, - arr.slice(index, Math.min(index + CHUNKSIZE, len)) - ); - index += CHUNKSIZE; - } - return parts; + return str; }; String["fromCodePoints"] = function fromCodePoints(arr) { - const CHUNKSIZE = 1 << 15; - let len = arr.length; - if (len <= CHUNKSIZE) { - return String.fromCodePoints.apply(String, arr); + // const CHUNKSIZE = 1 << 15; + // let len = arr.length; + // if (len <= CHUNKSIZE) { + // return String.fromCodePoints.apply(String, arr); + // } + // let index = 0; + // let parts = ''; + // do { + // const last = arr[index + CHUNKSIZE - 1]; + // const size = last >= 0xD800 && last < 0xDC00 ? CHUNKSIZE - 1 : CHUNKSIZE; + // parts += String.fromCharCode.apply(String, arr.slice(index, index += size)); + // len -= size; + // } while (len > CHUNKSIZE); + // return parts + String.fromCharCode.apply(String, arr.slice(index, index + len)); + let str = ''; + for (let i = 0, l = arr.length; i < l; i++) { + str += String.fromCodePoints(arr[i]); } - let index = 0; - let parts = ''; - do { - const last = arr[index + CHUNKSIZE - 1]; - const size = last >= 0xD800 && last < 0xDC00 ? CHUNKSIZE - 1 : CHUNKSIZE; - parts += String.fromCharCode.apply(String, arr.slice(index, index += size)); - len -= size; - } while (len > CHUNKSIZE); - return parts + String.fromCharCode.apply(String, arr.slice(index, index + len)); + return str; }; if (!String.prototype.replaceAll) { From 2529ce0e1faa36178c9737f09a5ec22c34ceefc2 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Jun 2020 01:22:48 +0300 Subject: [PATCH 06/10] cleanups --- std/portable/index.js | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/std/portable/index.js b/std/portable/index.js index f13bc6247a..b06d34def4 100644 --- a/std/portable/index.js +++ b/std/portable/index.js @@ -198,21 +198,6 @@ globalScope["changetype"] = function changetype(value) { }; String["fromCharCodes"] = function fromCharCodes(arr) { - // const CHUNKSIZE = 1 << 15; - // const len = arr.length; - // if (len <= CHUNKSIZE) { - // return String.fromCharCode.apply(String, arr); - // } - // let index = 0; - // let parts = ''; - // while (index < len) { - // parts += String.fromCharCode.apply( - // String, - // arr.slice(index, Math.min(index + CHUNKSIZE, len)) - // ); - // index += CHUNKSIZE; - // } - // return parts; let str = ''; for (let i = 0, l = arr.length; i < l; i++) { str += String.fromCharCode(arr[i]); @@ -221,20 +206,6 @@ String["fromCharCodes"] = function fromCharCodes(arr) { }; String["fromCodePoints"] = function fromCodePoints(arr) { - // const CHUNKSIZE = 1 << 15; - // let len = arr.length; - // if (len <= CHUNKSIZE) { - // return String.fromCodePoints.apply(String, arr); - // } - // let index = 0; - // let parts = ''; - // do { - // const last = arr[index + CHUNKSIZE - 1]; - // const size = last >= 0xD800 && last < 0xDC00 ? CHUNKSIZE - 1 : CHUNKSIZE; - // parts += String.fromCharCode.apply(String, arr.slice(index, index += size)); - // len -= size; - // } while (len > CHUNKSIZE); - // return parts + String.fromCharCode.apply(String, arr.slice(index, index + len)); let str = ''; for (let i = 0, l = arr.length; i < l; i++) { str += String.fromCodePoints(arr[i]); From 96f607e7c6ca28c71d8fa630d9021ac99a962919 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Jun 2020 01:25:20 +0300 Subject: [PATCH 07/10] fix --- std/portable/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/portable/index.js b/std/portable/index.js index b06d34def4..7674730e69 100644 --- a/std/portable/index.js +++ b/std/portable/index.js @@ -208,7 +208,7 @@ String["fromCharCodes"] = function fromCharCodes(arr) { String["fromCodePoints"] = function fromCodePoints(arr) { let str = ''; for (let i = 0, l = arr.length; i < l; i++) { - str += String.fromCodePoints(arr[i]); + str += String.fromCodePoint(arr[i]); } return str; }; From aa5119f00fbd1010ff15ab273b41454e1c69723c Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Jun 2020 01:35:28 +0300 Subject: [PATCH 08/10] revert --- std/portable/index.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/std/portable/index.js b/std/portable/index.js index 7674730e69..5733907a01 100644 --- a/std/portable/index.js +++ b/std/portable/index.js @@ -198,19 +198,38 @@ globalScope["changetype"] = function changetype(value) { }; String["fromCharCodes"] = function fromCharCodes(arr) { - let str = ''; - for (let i = 0, l = arr.length; i < l; i++) { - str += String.fromCharCode(arr[i]); + const CHUNKSIZE = 1 << 15; + const len = arr.length; + if (len <= CHUNKSIZE) { + return String.fromCharCode.apply(String, arr); } - return str; + let index = 0; + let parts = ''; + while (index < len) { + parts += String.fromCharCode.apply( + String, + arr.slice(index, Math.min(index + CHUNKSIZE, len)) + ); + index += CHUNKSIZE; + } + return parts; }; String["fromCodePoints"] = function fromCodePoints(arr) { - let str = ''; - for (let i = 0, l = arr.length; i < l; i++) { - str += String.fromCodePoint(arr[i]); + const CHUNKSIZE = 1 << 15; + let len = arr.length; + if (len <= CHUNKSIZE) { + return String.fromCodePoints.apply(String, arr); } - return str; + let index = 0; + let parts = ''; + do { + const last = arr[index + CHUNKSIZE - 1]; + const size = last >= 0xD800 && last < 0xDC00 ? CHUNKSIZE - 1 : CHUNKSIZE; + parts += String.fromCharCode.apply(String, arr.slice(index, index += size)); + len -= size; + } while (len > CHUNKSIZE); + return parts + String.fromCharCode.apply(String, arr.slice(index, index + len)); }; if (!String.prototype.replaceAll) { From 39f71a5d590abae38e0a833ad86b01ae4e66e4ef Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Jun 2020 01:50:25 +0300 Subject: [PATCH 09/10] fix --- std/portable/index.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/std/portable/index.js b/std/portable/index.js index 5733907a01..166f58c741 100644 --- a/std/portable/index.js +++ b/std/portable/index.js @@ -217,19 +217,20 @@ String["fromCharCodes"] = function fromCharCodes(arr) { String["fromCodePoints"] = function fromCodePoints(arr) { const CHUNKSIZE = 1 << 15; - let len = arr.length; + const len = arr.length; if (len <= CHUNKSIZE) { - return String.fromCodePoints.apply(String, arr); + return String.fromCodePoint.apply(String, arr); } let index = 0; let parts = ''; - do { - const last = arr[index + CHUNKSIZE - 1]; - const size = last >= 0xD800 && last < 0xDC00 ? CHUNKSIZE - 1 : CHUNKSIZE; - parts += String.fromCharCode.apply(String, arr.slice(index, index += size)); - len -= size; - } while (len > CHUNKSIZE); - return parts + String.fromCharCode.apply(String, arr.slice(index, index + len)); + while (index < len) { + parts += String.fromCodePoint.apply( + String, + arr.slice(index, Math.min(index + CHUNKSIZE, len)) + ); + index += CHUNKSIZE; + } + return parts; }; if (!String.prototype.replaceAll) { From 9ab782c8a2c6c1f035be676b7c1971ff6569b371 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Jun 2020 02:07:09 +0300 Subject: [PATCH 10/10] back to 1 << 13 --- std/portable/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/std/portable/index.js b/std/portable/index.js index 166f58c741..9271173249 100644 --- a/std/portable/index.js +++ b/std/portable/index.js @@ -198,7 +198,7 @@ globalScope["changetype"] = function changetype(value) { }; String["fromCharCodes"] = function fromCharCodes(arr) { - const CHUNKSIZE = 1 << 15; + const CHUNKSIZE = 1 << 13; const len = arr.length; if (len <= CHUNKSIZE) { return String.fromCharCode.apply(String, arr); @@ -216,7 +216,7 @@ String["fromCharCodes"] = function fromCharCodes(arr) { }; String["fromCodePoints"] = function fromCodePoints(arr) { - const CHUNKSIZE = 1 << 15; + const CHUNKSIZE = 1 << 13; const len = arr.length; if (len <= CHUNKSIZE) { return String.fromCodePoint.apply(String, arr);