New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 705990 link

Starred by 2 users

Issue metadata

Status: Archived
Owner: ----
Closed: Apr 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug



Sign in to add a comment

URLFetcherStringWriter grows by appending 4KB at a time which can be inefficient

Project Member Reported by brat...@opera.com, Mar 28 2017

Issue description

I 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 )
 

Comment 1 by brat...@opera.com, Mar 28 2017

Summary: URLFetcherStringWriter grows by appending 4KB at a time which can be inefficient (was: URLFetcherStringWriter grows by appending 4KB at a time (O(n^2)))
Sorry, not O(n^2). It depends on the growth factor of the libc's std::string implementation which is often 1.5 and then it takes somewhere between O(n) and O(n^2) time. Growth factor of 2 would be O(n) but then it will also waste a lot of memory on average.

I guess my point is that std::string is not the best place to grow a string unless you know its size from the beginning.
URLFetcherCore::OnResponseStarted() could pass total_response_bytes_ to response_writer_ as a hint and URLFetcherStringWriter could call std::string::reserve().

Comment 3 by mmenke@chromium.org, Mar 28 2017

Cc: mmenke@chromium.org
Labels: OS-All
Status: Available (was: Untriaged)
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.
Hello. I would like to work/contribute to this ticket. Can the owner of this issue have me onboard on it?

Comment 5 by mmenke@chromium.org, 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.
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.

Comment 7 by brat...@opera.com, 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.
Agreed.
Project Member

Comment 9 by sheriffbot@chromium.org, Apr 2 2018

Labels: Hotlist-Recharge-Cold
Status: Untriaged (was: Available)
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
Status: Archived (was: Untriaged)
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