Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 0118ad1

Browse files
committed
Use RapidJSON instead of Casablanca to parse JSON data
This decreases the host startup performance by a few milliseconds (at the order of 5ms) at the same time that the host libraries are reduced by almost 80KiB in size on a release build for x86-64/Linux. For comparison, these are the sizes with RapidJSON (release mode, Linux, x86-64, stripped): text data bss dec hex filename 306034 2292 1056 309382 4b886 libhostfxr.so 258763 2612 800 262175 4001f libhostpolicy.so And these are the sizes with Casablanca (release mode, Linux, x86-64, stripped): text data bss dec hex filename 340175 4340 1088 345603 54603 libhostfxr.so 294478 4636 840 299954 493b2 libhostpolicy.so RapidJSON is based off of commit d87b698d0fcc10a5f632ecbc80a9cb2a8fa094a5.
1 parent 8a9cc95 commit 0118ad1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+16992
-13013
lines changed

THIRD-PARTY-NOTICES.TXT

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,3 +629,22 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
629629
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
630630
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
631631
SOFTWARE.
632+
633+
634+
License notice for RapidJSON
635+
----------------------------
636+
637+
Tencent is pleased to support the open source community by making RapidJSON available.
638+
639+
Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
640+
641+
Licensed under the MIT License (the "License"); you may not use this file except
642+
in compliance with the License. You may obtain a copy of the License at
643+
644+
http://opensource.org/licenses/MIT
645+
646+
Unless required by applicable law or agreed to in writing, software distributed
647+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
648+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
649+
specific language governing permissions and limitations under the License.
650+

src/corehost/cli/comhost/CMakeLists.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(DOTNET_PROJECT_NAME "comhost")
99

1010
# Include directories
1111
include_directories(../fxr)
12-
include_directories(../json/casablanca/include)
12+
include_directories(../json)
1313

1414
# CMake does not recommend using globbing since it messes with the freshness checks
1515
set(SOURCES
@@ -18,16 +18,13 @@ set(SOURCES
1818
clsidmap.cpp
1919
../redirected_error_writer.cpp
2020
../fxr/fx_ver.cpp
21-
../json/casablanca/src/json/json.cpp
22-
../json/casablanca/src/json/json_parsing.cpp
23-
../json/casablanca/src/json/json_serialization.cpp
24-
../json/casablanca/src/utilities/asyncrt_utils.cpp
21+
../json_parser.cpp
2522
)
2623

2724
set(HEADERS
2825
comhost.h
2926
../fxr/fx_ver.h
30-
../json/casablanca/include/cpprest/json.h
27+
../json_parser.h
3128
)
3229

3330
if(WIN32)

src/corehost/cli/comhost/clsidmap.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
#include <wintrust.h>
1313
#include <Softpub.h>
1414

15-
#include <cpprest/json.h>
16-
using namespace web;
15+
#include "rapidjson/document.h"
16+
#include "rapidjson/istreamwrapper.h"
17+
#include "json_parser.h"
1718

1819
using comhost::clsid_map_entry;
1920
using comhost::clsid_map;
@@ -45,29 +46,21 @@ namespace
4546

4647
clsid_map parse_stream(_Inout_ pal::istream_t &json_map_raw)
4748
{
48-
skip_utf8_bom(&json_map_raw);
49+
json_parser_t json;
4950

50-
// Parse JSON
51-
json::value json_map;
52-
try
53-
{
54-
json_map = json::value::parse(json_map_raw);
55-
}
56-
catch (const json::json_exception&)
51+
if (!json.parse_stream(json_map_raw, _X("<embedded .clsidmap>")))
5752
{
5853
trace::error(_X("Embedded .clsidmap format is invalid"));
5954
throw HResultException{ StatusCode::InvalidConfigFile };
6055
}
6156

62-
json::object &json_obj = json_map.as_object();
63-
6457
// Process JSON and construct a map
6558
HRESULT hr;
6659
clsid_map mapping;
67-
for (std::pair<utility::string_t, json::value> &prop : json_obj)
60+
for (const auto &prop : json.document().GetObject())
6861
{
6962
CLSID clsidMaybe;
70-
hr = string_to_clsid(prop.first, clsidMaybe);
63+
hr = string_to_clsid(prop.name.GetString(), clsidMaybe);
7164
if (FAILED(hr))
7265
{
7366
assert(false && "Invalid CLSID");
@@ -79,14 +72,14 @@ namespace
7972

8073
e.clsid = clsidMaybe;
8174

82-
json::object &val = prop.second.as_object();
83-
e.assembly = val.at(_X("assembly")).as_string();
84-
e.type = val.at(_X("type")).as_string();
75+
const auto &val = prop.value.GetObject();
76+
e.assembly = val[_X("assembly")].GetString();
77+
e.type = val[_X("type")].GetString();
8578

8679
// Check if a ProgID was defined.
87-
auto prodIdMaybe = val.find(_X("progid"));
88-
if (prodIdMaybe != val.cend())
89-
e.progid = prodIdMaybe->second.as_string();
80+
const auto &prodIdMaybe = val.FindMember(_X("progid"));
81+
if (prodIdMaybe != val.MemberEnd())
82+
e.progid = prodIdMaybe->value.GetString();
9083

9184
mapping[clsidMaybe] = std::move(e);
9285
}

0 commit comments

Comments
 (0)