Skip to content

Instantly share code, notes, and snippets.

@marnix
Created June 13, 2020 08:01
Show Gist options
  • Save marnix/48cbcb00ced295c3e182c765f4a74939 to your computer and use it in GitHub Desktop.
Save marnix/48cbcb00ced295c3e182c765f4a74939 to your computer and use it in GitHub Desktop.
Reproduction scenario for nim --gc:arc performance difference
import memfiles
import streams
proc mmapStream(mmFileName: string): Stream =
return newMemMapFileStream(mmFileName)
iterator tokens(mmfile: Stream): string =
var i,j = 0
while not mmfile.atEnd():
let c = mmfile.readChar()
if c <= chr(32):
if i < j:
mmfile.setPosition(i)
let s = mmfile.peekStr(j-i)
yield s
mmfile.setPosition(j+1)
i = j+1
inc j
when isMainModule:
proc test(): void =
var n = 0
var l = 0
let mmStream = mmapStream("set.mm")
defer: mmstream.close()
for t in tokens(mmStream):
l += len(t)
inc n
echo(n," ",l)
test()
#!/bin/bash -xe
if [ ! -f set.mm ]
then
curl --location https://github.com/metamath/set.mm/raw/b0925f0afd5963577ea76b252cb6613c885b393d/set.mm > set.mm
fi
nim c --opt:speed -d:release arcperfdiff && time ./arcperfdiff
nim c --gc:arc --opt:speed -d:release arcperfdiff && time ./arcperfdiff
# both should output
#
# 4961591 29826787
#
# but with nim 1.2.0 binaries from nixpkgs, for me
# the default version takes ~1 second,
# while the --gc:arc version takes 5+ seconds.
@zevv
Copy link

zevv commented Jun 13, 2020

Compile with -d:danger instead of -d:release, there's still a ton of boundary checks in the inner loop causing slow downs.

@marnix
Copy link
Author

marnix commented Jun 13, 2020

Thanks! Is there a GitHub issue for this, or should I create one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment