gc tweaking to gain a few percent of performance

This commit is contained in:
Araq 2011-05-07 22:13:24 +02:00
commit 73c3551766
13 changed files with 183 additions and 153 deletions

View file

@ -677,8 +677,8 @@ proc genProcAux(m: BModule, prc: PSym) =
if optStackTrace in prc.options: app(generatedProc, deinitFrame(p))
if (optProfiler in prc.options) and (gCmd != cmdCompileToLLVM):
appf(generatedProc,
"profileData[$1].total += elapsed(getticks(), NIM_profilingStart);$n",
[toRope(prc.loc.a)])
"profileData[$1].total += elapsed(getticks(), NIM_profilingStart);$n",
[toRope(prc.loc.a)])
app(generatedProc, returnStmt)
app(generatedProc, '}' & tnl)
app(m.s[cfsProcs], generatedProc)

View file

@ -100,19 +100,16 @@ proc crcFromBuf(buf: Pointer, length: int): TCrc32 =
proc crcFromFile(filename: string): TCrc32 =
const
bufSize = 8 * 1024
bufSize = 8000 # don't use 8K for the memory allocator!
var
bin: tfile
buf: Pointer
readBytes: int
p: PByteArray
result = InitCrc32
if not open(bin, filename):
return # not equal if file does not exist
buf = alloc(BufSize)
p = cast[PByteArray](buf)
var buf = alloc(BufSize)
var p = cast[PByteArray](buf)
while true:
readBytes = readBuffer(bin, buf, bufSize)
var readBytes = readBuffer(bin, buf, bufSize)
for i in countup(0, readBytes - 1): result = updateCrc32(p[i], result)
if readBytes != bufSize: break
dealloc(buf)

View file

@ -50,7 +50,7 @@ proc ProcessCmdLine(pass: TCmdLinePass, command, filename: var string) =
rawMessage(errArgsNeedRunOption, [])
proc HandleCmdLine() =
var start = getTime()
var start = epochTime()
if paramCount() == 0:
writeCommandLineUsage()
else:
@ -73,7 +73,8 @@ proc HandleCmdLine() =
if gCmd == cmdRun:
tccgen.run()
if gCmd notin {cmdInterpret, cmdRun}:
rawMessage(hintSuccessX, [$gLinesCompiled, $(getTime() - start)])
rawMessage(hintSuccessX, [$gLinesCompiled,
formatFloat(epochTime() - start, ffDecimal, 3)])
if optRun in gGlobalOptions:
when defined(unix):
var prog = "./" & quoteIfContainsWhite(changeFileExt(filename, ""))
@ -81,6 +82,7 @@ proc HandleCmdLine() =
var prog = quoteIfContainsWhite(changeFileExt(filename, ""))
execExternalProgram(prog & ' ' & arguments)
#GC_disableMarkAndSweep()
cmdLineInfo = newLineInfo("command line", -1, -1)
condsyms.InitDefines()
HandleCmdLine()

View file

@ -1,7 +1,7 @@
#
#
# The Nimrod Compiler
# (c) Copyright 2008 Andreas Rumpf
# (c) Copyright 2011 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@ -12,13 +12,7 @@
import
nhashes, ast, astalgo, types
proc NodeTableGet*(t: TNodeTable, key: PNode): int
proc NodeTablePut*(t: var TNodeTable, key: PNode, val: int)
proc NodeTableTestOrSet*(t: var TNodeTable, key: PNode, val: int): int
# implementation
proc hashTree(n: PNode): THash =
result = 0
if n == nil: return
result = ord(n.kind)
case n.kind
@ -41,7 +35,6 @@ proc hashTree(n: PNode): THash =
result = concHash(result, hashTree(n.sons[i]))
proc TreesEquivalent(a, b: PNode): bool =
result = false
if a == b:
result = true
elif (a != nil) and (b != nil) and (a.kind == b.kind):
@ -60,36 +53,31 @@ proc TreesEquivalent(a, b: PNode): bool =
if result: result = sameTypeOrNil(a.typ, b.typ)
proc NodeTableRawGet(t: TNodeTable, k: THash, key: PNode): int =
var h: THash
h = k and high(t.data)
var h: THash = k and high(t.data)
while t.data[h].key != nil:
if (t.data[h].h == k) and TreesEquivalent(t.data[h].key, key):
return h
h = nextTry(h, high(t.data))
result = - 1
result = -1
proc NodeTableGet(t: TNodeTable, key: PNode): int =
var index: int
index = NodeTableRawGet(t, hashTree(key), key)
proc NodeTableGet*(t: TNodeTable, key: PNode): int =
var index = NodeTableRawGet(t, hashTree(key), key)
if index >= 0: result = t.data[index].val
else: result = low(int)
proc NodeTableRawInsert(data: var TNodePairSeq, k: THash, key: PNode, val: int) =
var h: THash
h = k and high(data)
proc NodeTableRawInsert(data: var TNodePairSeq, k: THash, key: PNode,
val: int) =
var h: THash = k and high(data)
while data[h].key != nil: h = nextTry(h, high(data))
assert(data[h].key == nil)
data[h].h = k
data[h].key = key
data[h].val = val
proc NodeTablePut(t: var TNodeTable, key: PNode, val: int) =
var
index: int
n: TNodePairSeq
k: THash
k = hashTree(key)
index = NodeTableRawGet(t, k, key)
proc NodeTablePut*(t: var TNodeTable, key: PNode, val: int) =
var n: TNodePairSeq
var k: THash = hashTree(key)
var index = NodeTableRawGet(t, k, key)
if index >= 0:
assert(t.data[index].key != nil)
t.data[index].val = val
@ -103,13 +91,10 @@ proc NodeTablePut(t: var TNodeTable, key: PNode, val: int) =
NodeTableRawInsert(t.data, k, key, val)
inc(t.counter)
proc NodeTableTestOrSet(t: var TNodeTable, key: PNode, val: int): int =
var
index: int
n: TNodePairSeq
k: THash
k = hashTree(key)
index = NodeTableRawGet(t, k, key)
proc NodeTableTestOrSet*(t: var TNodeTable, key: PNode, val: int): int =
var n: TNodePairSeq
var k: THash = hashTree(key)
var index = NodeTableRawGet(t, k, key)
if index >= 0:
assert(t.data[index].key != nil)
result = t.data[index].val