URLFetcherStringWriter grows by appending 4KB at a time which can be inefficient |
||||
Issue descriptionI studied oom crashes when I saw us running out of memory in net::URLFetcherStringWriter::Write. Studying the code we end up doing std::string::append() with 4KB at a time (or less) until the data has ended or we run out of memory or time. net::URLFetcherCore::OnReadCompleted which has a 4KB buffer (kBufferSize) calls net::URLFetcherCore::WriteBuffer which forwards to net::URLFetcherStringWriter::Write which does std::string::append which reallocates the buffer and copies. Looking at chrome::histograms, and UrlFetcher.StringResponseSize which is reported in KB, it's not used often but used with data in the 1-4 MB class. That is a lot of reallocations. (internal ref: 998373c8-a719-4a8b-999a-6b5322170328 )
,
Mar 28 2017
URLFetcherCore::OnResponseStarted() could pass total_response_bytes_ to response_writer_ as a hint and URLFetcherStringWriter could call std::string::reserve().
,
Mar 28 2017
I'd rather get things using it for more than a couple hundred K off of using in-memory buffers, and add a hard-limit for all consumers that can't be overridden. The whole download stuff into memory until we crash thing just seems like a really bad API, particularly as some consumers use it for unencrypted HTTP requests. See also issue 535601.
,
Mar 29 2017
Hello. I would like to work/contribute to this ticket. Can the owner of this issue have me onboard on it?
,
Mar 29 2017
claudiomdsjr: Are you thinking of bratell's (entirely reasonable) solution to improve the status quo, or my significantly more involved pie-in-the-sky suggestion? I'm assuming the former, though I suppose they aren't really exclusive of each other.
,
Mar 29 2017
mmenke: I don't mind either implementations in particular. I would be more than glad to collaborate in both. I can see the trade off of both approaches to this issue, and as you recognised, the latter will require more careful planning, but I wouldn't mind being involved on that as well. I do use //net a lot on many projects, so I'm familiar with its inner workings, however I've been using Chromium code for so long that I feel I should really be involved with it, rather than just consuming it for personal purposes... I'm just trying to get more involved with Chromium, and this ticket looked reasonably familiar to me.
,
Mar 29 2017
I have no strong opinions here. I just stumbled upon this as a possible area of improvement while looking at out-of-memory issues and I'd welcome anyone improving it. pauljensen's suggestion to preallocate the buffer seems like a good one, and restricting the API to "safe" usage also seems like a good one and neither excludes the other.
,
Mar 29 2017
Agreed.
,
Apr 2 2018
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue. Sorry for the inconvenience if the bug really should have been left as Available. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Apr 11 2018
Archiving this - URLFetcher will no longer be used in Chrome in the foreseeable future. Unclear if we'll be able to remove it entirely. |
||||
►
Sign in to add a comment |
||||
Comment 1 by brat...@opera.com
, Mar 28 2017