Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/vcpkg/base/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ namespace vcpkg::Json
static Value integer(int64_t i) noexcept;
static Value number(double d) noexcept;
static Value string(std::string&& s) noexcept;
static Value string_valid(std::string&& s) noexcept;
template<class StringLike, std::enable_if_t<std::is_constructible_v<StringView, const StringLike&>, int> = 0>
static Value string(const StringLike& s) noexcept
{
Expand Down
9 changes: 8 additions & 1 deletion src/vcpkg/base/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ namespace vcpkg::Json
val.underlying_ = std::make_unique<ValueImpl>(ValueKindConstant<VK::String>(), std::move(s));
return val;
}
Value Value::string_valid(std::string&& s) noexcept
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there is a fairly extreme perf cost from the check on 330 I'm not really seeing a good reason to add this API. If there is an extreme perf reason, perhaps we should consider altering how that assertion works rather than adding a new API footgun like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not much necessary. I am investigating why sometimes vcpkg search is slow and then find this json::parse_value function

When I pref vcpkg search a, the json::parse_value function only costs about 5%-10%

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing you're using manifest mode? In that case the reason search is awfully slow is that we end up launching a git process per port to extract the tree sha. I had some work in progress to use git mktree to replace N git invocations with 2 git invocations but I haven't had time to get back to that.

Also unfortunately child process launch time etc. won't be detected by a sampling based profiler like this since it only cares about CPU time in the process in question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using the classic mode, and most of the time vcpkg search takes only < 500ms, but occasionally it's slow, up to 5 seconds I guess

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you take your profile during one of the times where it was slow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, currently I can't reproduce when build vcpkg from source

"slow" only occured when using offical vcpkg in classic mode, and not occured on all of my PCs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I can reproduce when the first time I compile after I reboot, the search method costs about 5s

{
Value val;
val.underlying_ = std::make_unique<ValueImpl>(ValueKindConstant<VK::String>(), std::move(s));
return val;
}
Value Value::array(Array&& arr) noexcept
{
Value val;
Expand Down Expand Up @@ -699,6 +705,7 @@ namespace vcpkg::Json
}

add_error(msg::format(msgUnexpectedEOFMidString));
vcpkg::Checks::msg_exit_with_message(VCPKG_LINE_INFO, msgInvalidString);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is quite clearly trying to return the error message rather than terminate, I don't think elevating an error into termination is appropriate, particularly when this can happen from whatever user supplied input rather than a bug in the tool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently there are only two functions call json::parse_string, when the string is invalid:

  • json::parse_value -> Value::string -> json::parse_string, it will also terminate in Value::string
  • json::parse_object -> json::parse_kv_pair -> json::parse_string, it will not terminate, but continue to create a invalid kv_pair in json::parse_kv_pair, and insert it in json::parse_object

I don't think elevating an error into termination is appropriate

I agree with this, but seems json::parse_value and json::parse_object don't behave the same

return res;
}

Expand Down Expand Up @@ -1036,7 +1043,7 @@ namespace vcpkg::Json
{
case '{': return parse_object();
case '[': return parse_array();
case '"': return Value::string(parse_string());
case '"': return Value::string_valid(parse_string());
case 'n':
case 't':
case 'f': return parse_keyword();
Expand Down
Loading