This repository has been archived by the owner on Oct 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Merge chakra-core/ChakraCore@c6b3f201b1] [MERGE #3751 @obastemur] pe…
…rf: Improve JSON.stringify performance Merge pull request #3751 from obastemur:fjs Kraken/json-stringify-* perf ~25% better. Acme Air - LTO gain ~1.5% PR Details: - Improve `replacer != function && !HasObjectArray` case. (most common use of JSON.stringify) - Add JSON.stringify test cases for ObjectArray, toJSON, and replacer function - IsNumericPropertyId: fast path for internal properties - use requestContext instead of instance->scriptContext - use wmemcpy instead of memcpy
- Loading branch information
Showing
12 changed files
with
220 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
|
||
var TEST = function(a, b) { | ||
if (a != b) { | ||
throw new Error(a + " != " + b); | ||
} | ||
} | ||
|
||
var obj = { str:6 }; | ||
obj[0] = 'value0' | ||
obj[6] = 'value6'; | ||
TEST(JSON.stringify(obj, function(k, v) { | ||
if (!k) return v; | ||
return v + 1 | ||
}), '{"0":"value01","6":"value61","str":7}'); | ||
|
||
// test ObjectArray | ||
TEST(JSON.stringify({0:0, 1:1, "two":2}), '{"0":0,"1":1,"two":2}') | ||
|
||
var a = new Object(); | ||
|
||
function replacer(k, v) | ||
{ | ||
return v; | ||
} | ||
|
||
var until = (!WScript.Platform || WScript.Platform.BUILD_TYPE == 'Debug') ? 12 : 1290; | ||
for (var i = 0; i < until; i++) | ||
{ | ||
a[i + 10] = 0; | ||
} | ||
|
||
TEST(JSON.stringify(a, replacer).substring(0,20), '{"10":0,"11":0,"12":'); | ||
|
||
console.log("PASS") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
|
||
var TEST = function(a, b) { | ||
if (a != b) { | ||
throw new Error(a + " != " + b); | ||
} | ||
} | ||
|
||
var fnc = function(n) { this.number = n }; | ||
fnc.prototype.toJSON = function() { | ||
return this.number.toString(); | ||
} | ||
|
||
// test - function prototype new instance | ||
TEST("\"1\"", JSON.stringify(new fnc(1))) | ||
|
||
// test - pre-post alter Date toJSON definition | ||
var dateString = JSON.stringify(new Date(0)); | ||
TEST("1970", dateString.substr(dateString.indexOf("1970"), 4)) | ||
|
||
Date.prototype.toJSON = 1; | ||
TEST("{}", JSON.stringify(new Date(0))) | ||
|
||
delete Date.prototype.toJSON | ||
TEST("{}", JSON.stringify(new Date(0))) | ||
|
||
// test - use from Object prototype | ||
Object.prototype.toJSON = function() { return 2; } | ||
delete fnc.prototype.toJSON; | ||
TEST(2, JSON.stringify(new fnc(1))) | ||
|
||
// test - symbol | ||
Object.prototype[Symbol("toJSON")] = function() { return 3; } | ||
TEST(2, JSON.stringify(new fnc(1))) | ||
|
||
console.log("PASS") |