comparison mercurial/wireproto.py @ 29151:7996c3acc33b

wireproto: optimize handling of large batch responses Now that batch can be used by remotefilelog, the quadratic string copying this was doing was actually disastrous. In my local testing, fetching a 56 meg file used to take 3 minutes, and now takes only a few seconds.
author Augie Fackler <augie@google.com>
date Thu, 12 May 2016 09:39:14 -0400
parents 032c4c2f802a
children ead25aa27a43
comparison
equal deleted inserted replaced
29150:0e9ed09f5fe9 29151:7996c3acc33b
229 for op, argsdict in req: 229 for op, argsdict in req:
230 args = ','.join('%s=%s' % (escapearg(k), escapearg(v)) 230 args = ','.join('%s=%s' % (escapearg(k), escapearg(v))
231 for k, v in argsdict.iteritems()) 231 for k, v in argsdict.iteritems())
232 cmds.append('%s %s' % (op, args)) 232 cmds.append('%s %s' % (op, args))
233 rsp = self._callstream("batch", cmds=';'.join(cmds)) 233 rsp = self._callstream("batch", cmds=';'.join(cmds))
234 # TODO this response parsing is probably suboptimal for large 234 chunk = rsp.read(1024)
235 # batches with large responses. 235 work = [chunk]
236 work = rsp.read(1024)
237 chunk = work
238 while chunk: 236 while chunk:
239 while ';' in work: 237 while ';' not in chunk and chunk:
240 one, work = work.split(';', 1) 238 chunk = rsp.read(1024)
239 work.append(chunk)
240 merged = ''.join(work)
241 while ';' in merged:
242 one, merged = merged.split(';', 1)
241 yield unescapearg(one) 243 yield unescapearg(one)
242 chunk = rsp.read(1024) 244 chunk = rsp.read(1024)
243 work += chunk 245 work = [merged, chunk]
244 yield unescapearg(work) 246 yield unescapearg(''.join(work))
245 247
246 def _submitone(self, op, args): 248 def _submitone(self, op, args):
247 return self._call(op, **args) 249 return self._call(op, **args)
248 250
249 def iterbatch(self): 251 def iterbatch(self):