Skip to content

Commit fdf3649

Browse files
committed
Undoing a synchronous wait removal due to massive performance impact in streams.
1 parent f2d22aa commit fdf3649

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

Release/include/cpprest/streams.h

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -786,20 +786,22 @@ namespace Concurrency { namespace streams
786786
});
787787
};
788788

789-
auto update = [=](int_type ch) mutable -> pplx::task<bool>
789+
auto update = [=](int_type ch) mutable
790790
{
791-
if (ch == ::concurrency::streams::char_traits<CharType>::eof()) return pplx::task_from_result(false);
792-
if (ch == delim) return pplx::task_from_result(false);
791+
if (ch == ::concurrency::streams::char_traits<CharType>::eof()) return false;
792+
if (ch == delim) return false;
793793

794794
_locals->outbuf[_locals->write_pos] = static_cast<CharType>(ch);
795795
_locals->write_pos += 1;
796796

797797
if (_locals->is_full())
798798
{
799-
return flush().then([] { return true; });
799+
// Flushing synchronously because performance is terrible if we
800+
// schedule an empty task. This isn't on a user's thread.
801+
flush().get();
800802
}
801803

802-
return pplx::task_from_result(true);
804+
return true;
803805
};
804806

805807
auto loop = pplx::details::do_while([=]() mutable -> pplx::task<bool>
@@ -813,7 +815,10 @@ namespace Concurrency { namespace streams
813815
break;
814816
}
815817

816-
return update(ch);
818+
if (!update(ch))
819+
{
820+
return pplx::task_from_result(false);
821+
}
817822
}
818823
return buffer.bumpc().then(update);
819824
});
@@ -855,23 +860,25 @@ namespace Concurrency { namespace streams
855860

856861
auto update = [=](typename concurrency::streams::char_traits<CharType>::int_type ch) mutable
857862
{
858-
if (ch == concurrency::streams::char_traits<CharType>::eof()) return pplx::task_from_result(false);
859-
if (ch == '\n') return pplx::task_from_result(false);
863+
if (ch == concurrency::streams::char_traits<CharType>::eof()) return false;
864+
if (ch == '\n') return false;
860865
if (ch == '\r')
861866
{
862867
_locals->saw_CR = true;
863-
return pplx::task_from_result(true);
868+
return true;
864869
}
865870

866871
_locals->outbuf[_locals->write_pos] = static_cast<CharType>(ch);
867872
_locals->write_pos += 1;
868873

869874
if (_locals->is_full())
870875
{
871-
return flush().then([] { return true; });
876+
// Flushing synchronously because performance is terrible if we
877+
// schedule an empty task. This isn't on a user's thread.
878+
flush().wait();
872879
}
873880

874-
return pplx::task_from_result(true);
881+
return true;
875882
};
876883

877884
auto update_after_cr = [=] (typename concurrency::streams::char_traits<CharType>::int_type ch) mutable -> pplx::task<bool>
@@ -910,7 +917,10 @@ namespace Concurrency { namespace streams
910917
if (ch == req_async)
911918
break;
912919

913-
return update(ch);
920+
if (!update(ch))
921+
{
922+
return pplx::task_from_result(false);
923+
}
914924
}
915925

916926
if (_locals->saw_CR)
@@ -1132,12 +1142,14 @@ pplx::task<void> concurrency::streams::_type_parser_base<CharType>::_skip_whites
11321142
{
11331143
if (buffer.sbumpc() == req_async)
11341144
{
1135-
return buffer.nextc().then([](int_type) { return true; });
1145+
// Synchronously because performance is terrible if we
1146+
// schedule an empty task. This isn't on a user's thread.
1147+
buffer.nextc().wait();
11361148
}
1137-
return pplx::task_from_result(true);
1149+
return true;
11381150
}
11391151

1140-
return pplx::task_from_result(false);
1152+
return false;
11411153
};
11421154

11431155
auto loop = pplx::details::do_while([=]() mutable -> pplx::task<bool>
@@ -1149,7 +1161,10 @@ pplx::task<void> concurrency::streams::_type_parser_base<CharType>::_skip_whites
11491161
if (ch == req_async)
11501162
break;
11511163

1152-
return update(ch);
1164+
if (!update(ch))
1165+
{
1166+
return pplx::task_from_result(false);
1167+
}
11531168
}
11541169
return buffer.getc().then(update);
11551170
});

0 commit comments

Comments
 (0)