##// END OF EJS Templates
remotephase: fast path newheads computation in simple case (issue5964)...
remotephase: fast path newheads computation in simple case (issue5964) Changeset 88efb7d6bcb6 fixed the logic of `phases.newheads` but greatly regressed its performance (up to many order of magnitude). The first step to fix the regression is to exit early when there is no work to do. If there are no heads to filter or not roots to filter them, we don't have to do any work. This fixes the regression when talking to an all public changeset. The performance is even better than before. pypy, compared to an all public repo ------------------------------------ 8eeed92475d5: 0.005758 seconds 88efb7d6bcb6: 0.602517 seconds (x104) this code: 0.001508 seconds (-74% from base) mercurial compared to an all public repo ---------------------------------------- 8eeed92475d5: 0.000577 seconds 88efb7d6bcb6: 0.185316 seconds (x321) this code: 0.000150 seconds (-74% from base) The performance of newheads, when actual computations are required, is fixed in the next changeset.

File last commit:

r28836:3f45488d default
r39181:c89e2fb2 stable
Show More
hgclient.py
123 lines | 3.3 KiB | text/x-python | PythonLexer
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 # A minimal client for Mercurial's command server
Pulkit Goyal
hgclient: use absolute_import and print_function
r28355 from __future__ import absolute_import, print_function
import os
import signal
import socket
import struct
import subprocess
import sys
import time
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
timeless
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
r28836 try:
import cStringIO as io
stringio = io.StringIO
except ImportError:
import io
stringio = io.StringIO
Yuya Nishihara
test-commandserver: allow check() to make connection in different way...
r22992 def connectpipe(path=None):
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 cmdline = ['hg', 'serve', '--cmdserver', 'pipe']
if path:
cmdline += ['-R', path]
server = subprocess.Popen(cmdline, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
return server
Yuya Nishihara
test-commandserver: add connector for unix domain socket server...
r22993 class unixconnection(object):
def __init__(self, sockpath):
self.sock = sock = socket.socket(socket.AF_UNIX)
sock.connect(sockpath)
self.stdin = sock.makefile('wb')
self.stdout = sock.makefile('rb')
def wait(self):
self.stdin.close()
self.stdout.close()
self.sock.close()
class unixserver(object):
def __init__(self, sockpath, logpath=None, repopath=None):
self.sockpath = sockpath
cmdline = ['hg', 'serve', '--cmdserver', 'unix', '-a', sockpath]
if repopath:
cmdline += ['-R', repopath]
if logpath:
stdout = open(logpath, 'a')
stderr = subprocess.STDOUT
else:
stdout = stderr = None
self.server = subprocess.Popen(cmdline, stdout=stdout, stderr=stderr)
# wait for listen()
while self.server.poll() is None:
if os.path.exists(sockpath):
break
time.sleep(0.1)
def connect(self):
return unixconnection(self.sockpath)
def shutdown(self):
os.kill(self.server.pid, signal.SIGTERM)
self.server.wait()
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 def writeblock(server, data):
server.stdin.write(struct.pack('>I', len(data)))
server.stdin.write(data)
server.stdin.flush()
def readchannel(server):
data = server.stdout.read(5)
if not data:
raise EOFError
channel, length = struct.unpack('>cI', data)
if channel in 'IL':
return channel, length
else:
return channel, server.stdout.read(length)
def sep(text):
return text.replace('\\', '/')
def runcommand(server, args, output=sys.stdout, error=sys.stderr, input=None,
outfilter=lambda x: x):
Pulkit Goyal
hgclient: use absolute_import and print_function
r28355 print('*** runcommand', ' '.join(args))
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 sys.stdout.flush()
server.stdin.write('runcommand\n')
writeblock(server, '\0'.join(args))
if not input:
timeless
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
r28836 input = stringio()
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
while True:
ch, data = readchannel(server)
if ch == 'o':
output.write(outfilter(data))
output.flush()
elif ch == 'e':
error.write(data)
error.flush()
elif ch == 'I':
writeblock(server, input.read(data))
elif ch == 'L':
writeblock(server, input.readline(data))
elif ch == 'r':
ret, = struct.unpack('>i', data)
if ret != 0:
Pulkit Goyal
hgclient: use absolute_import and print_function
r28355 print(' [%d]' % ret)
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 return ret
else:
Pulkit Goyal
hgclient: use absolute_import and print_function
r28355 print("unexpected channel %c: %r" % (ch, data))
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 if ch.isupper():
return
Yuya Nishihara
test-commandserver: allow check() to make connection in different way...
r22992 def check(func, connect=connectpipe):
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 sys.stdout.flush()
Yuya Nishihara
test-commandserver: remove unused repopath argument from check()...
r22991 server = connect()
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 try:
return func(server)
finally:
server.stdin.close()
server.wait()