Re: Memory usage skyrocketed with nim 0.18.0 (in my async tcp service test)

2018-04-03 Thread aguspiza2
indeed no changes:


sudo pmap 28234
28234:   ./httpasync0181
561967f7a000124K r-x-- httpasync0181
561968198000  4K r httpasync0181
561968199000  4K rw--- httpasync0181
56196819a000 32K rw---   [ anon ]
561968b41000124K rw---   [ anon ]
7fde9f0e3000  84164K rw---   [ anon ]
7fdea4314000   2172K r-x-- libgc.so.1.0.3
7fdea4533000  4K r libgc.so.1.0.3
7fdea4534000  4K rw--- libgc.so.1.0.3
7fdea4535000264K rw---   [ anon ]
7fdea457c000548K r-x-- ld-musl-x86_64.so.1
7fdea460c000   1472K rw---   [ anon ]
7fdea477c000  4K r--s- localtime
7fdea477f000  8K -   [ anon ]
7fdea4781000 84K rw---   [ anon ]
7fdea4796000  8K -   [ anon ]
7fdea4798000 84K rw---   [ anon ]
7fdea47ad000  8K -   [ anon ]
7fdea47af000340K rw---   [ anon ]
7fdea4804000  4K r ld-musl-x86_64.so.1
7fdea4805000  4K rw--- ld-musl-x86_64.so.1
7fdea4806000 12K rw---   [ anon ]
7fffec4e9000132K rw---   [ pila ]
7fffec5ec000  8K r   [ anon ]
7fffec5ee000  8K r-x--   [ anon ]
ff60  4K r-x--   [ anon ]
 total89624K



best practice for writing tests: isMainModule? runnableExamples? tests/ ?

2018-04-03 Thread timothee
What's the best practice for writing tests?

  * within module that's being tested (inside isMainModule block)?
  * within function that's being tested (inside runnableExamples block)?
  * inside tests/ ?



Will alll of these be automatically run by CI and locally with ./koch tests?

pros and cons for each?

what are the guidelines for when to prefer one or the other?

I see all 3 being used in Nim codebase, but consistency is good, this should 
belong in README.md or in CONTRIBUTING.md ; it could simply be: for tests, do 
as done proc X in module Y. Even if legacy code doesn't follow these 
guidelines, new code should follow whatever latest best practices as outlined 
in some easy to find authoritative source

My preference would be to do as D's unittest does, which is to have tests be as 
local as possible to what's being tested (ie runnableExamples) whenever 
possible unless there's a good reason not to for a specific thing to test. Does 
runnableExamples have any drawback? (eg in terms of compile/runtime performance 
in the case where we are not running tests?) 


Re: module name collision across nimble packages

2018-04-03 Thread Araq
Indeed, you cannot use `std.times.callFun()` as an expression. Nim is not D, 
I'm sorry.


Re: module name collision across nimble packages

2018-04-03 Thread timothee
argument for dots: it's nice that declaration matches usage: 
std.times.callFun() ; whereas we can't use: std/times.CallFun()


Re: Run tests

2018-04-03 Thread timothee
to compile and run and individual test file in a locally modified nim repo: 


nim c --lib:lib -r tests/stdlib/talgorithm.nim



Re: NimShooter

2018-04-03 Thread erasmo85
> Press A to start
> 
> Actually you have to press Z

Ups, sorry, in the retro console mentality the A key is (almost) always the Z 
key on a pc keyboard... I should fix that

> The game looks cool, but is really hardcore.

I like that way, for me if a game is not hardcore it has no sense 


Re: module name collision across nimble packages

2018-04-03 Thread Araq
I don't like the dots and think we should deprecate them. 


Re: atomic and ref pointer

2018-04-03 Thread Araq
Well if you `protect` and `dispose` the `ref` properly, you can exchange it 
between threads. For this to work out it needs to be casted to `pointer` or 
`ptr`.


Re: NimShooter

2018-04-03 Thread Arrrrrrrrr
> Press A to start
> 
> Actually you have to press Z

The game looks cool, but is really hardcore.


Re: how to get unmodified / uninterpreted source code/AST of expression in macro?

2018-04-03 Thread mratsim
That's actually a regular question (pain point?) regarding macros.

The current way is to preprocess using an untyped macro, and then 
dispatch/getAST from a typed macro when you need type resolution.

I remember seeing some discussion to ease that but they are pretty buried.


Re: how to skip all the `Hint: foo [Processing]` during compilation?

2018-04-03 Thread timothee
thanks! embarassed to have asked this... somehow hint[Conf]=off doesn't seem to 
work (the other ones work); maybe because without that hint it'd be hard to see 
which configs are being used; in any case would be nice to mention this in nim 
--advanced entry for hints


Re: how to get unmodified / uninterpreted source code/AST of expression in macro?

2018-04-03 Thread timothee
> It works when the macro parameter is untyped,

thanks @rpowers and @mashingan, using untyped instead of typed works (but I was 
using typed because of your other answer from 
[https://forum.nim-lang.org/t/3701/1#23070](https://forum.nim-lang.org/t/3701/1#23070)
 to allow if x.getTypeInst.typeKind != ntyVoid: to make it work on empty 
arguments; I guess I need further processing to have both unmodified source AST 
and allow for void typed arguments)


Re: how to skip all the `Hint: foo [Processing]` during compilation?

2018-04-03 Thread cblake
You can also put in [any of your 
nim.cfgs](https://nim-lang.org/docs/nimc.html#compiler-usage-configuration-files)


hint[Processing]=off


You can also disable other categories of diagnostics besides "Processing" 
similarly.


Re: how to skip all the `Hint: foo [Processing]` during compilation?

2018-04-03 Thread mashingan
maybe like this?


nim c --hints:off themodule



how to skip all the `Hint: foo [Processing]` during compilation?

2018-04-03 Thread timothee
\--verbosity:0 didn't help also, I don't wanna pipe / filter (not good to rely 
on shell for that: error prone, can mess up with coloring, not cross platform) 
ideally there'd be some extensible option, eg:


nim c 
--disp_hints:Processing=false,SuccessX=false,XDeclaredButNotUsed=false,Link=false,Conf=false



Re: Memory usage skyrocketed with nim 0.18.0 (in my async tcp service test)

2018-04-03 Thread jcosborn
Actually, the allocator fixes, I think, would only apply to large (>1 GB) 
memory use, so that may not be relevant here. I'm sorry if I lead you down the 
wrong path.


Re: How to rewrite this in Nim style?

2018-04-03 Thread mashingan
@Krux02, did you replied the TS code or my tokenize2 ?

For removing ref in ref object, I agree. I usually code in value-type instead 
ref-type, as I only use ref-type when it's usually wrap around costly resource, 
like socket, heaped memory, file i/o.

Agree too with coding by setting pointer for current and latest , that style is 
discouraged.


Re: how to get unmodified / uninterpreted source code/AST of expression in macro?

2018-04-03 Thread mashingan
This is from tutorial


import macros

macro debug(x: varargs[untyped]): typed =
  result = newStmtList()
  for s in x:
  var slit = s.toStrLit
  var stringExpr = slit.repr
  
  echo stringExpr & " okay"
  result.add newCall("write", newIdentNode("stdout"), slit)
  result.add newCall("write", newIdentNode("stdout"), newStrLitNode(": 
"))
  result.add newCall("writeLine", newIdentNode("stdout"), s)


var x = 1

proc one(): int = 1

debug(1+1)# prints 1 + 1: 2
debug(x+1)# prints x + 1: 2
debug(one() + 1)  # prints one() + 1: 2


What's the problem with toStrLit you have?


Re: how to get unmodified / uninterpreted source code/AST of expression in macro?

2018-04-03 Thread rpowers
It works when the macro parameter is untyped, I guess constant folding happens 
during the typing process:


import macros

macro mylog(x:untyped): untyped =
result = newNimNode(nnkStmtList, x)
result.add(newCall("write", newIdentNode("stdout"), toStrLit(x)))
result.add(newCall("write", newIdentNode("stdout"), newStrLitNode(":")))
result.add(newCall("writeLine", newIdentNode("stdout"), x))

var x=1
mylog(x+1) # x + 1:2  (OK but I'd rather want exact source code with 
spacing eg: `x+1:2`)
mylog(1+1) # 2:2 (not OK, I want: 1+1: 2)



Re: Memory usage skyrocketed with nim 0.18.0 (in my async tcp service test)

2018-04-03 Thread aguspiza2
Thanks Araq, right now I am using "clients" to avoid deallocating memory, so 
that I can get peak memory use. In the future, it will be used to dispatch 
messages to specific connected clients. This service should also remove clients 
from that sequence when they disconnect. Sorry, I will try to clean up the code 
so that the test makes more "sense", this may help me to find out which part is 
allocating those extra 70MB (Sorry for the long post): 


sudo pmap 26153
26153:   httpasync/src/httpasync018
556fff75a000124K r-x-- httpasync018
556fff978000  4K r httpasync018
556fff979000  4K rw--- httpasync018
556fff97a000 32K rw---   [ anon ]
557000ed2000124K rw---   [ anon ]
7f2806a93000  84164K rw---   [ anon ]
7f280bcc4000   2172K r-x-- libgc.so.1.0.3
7f280bee3000  4K r libgc.so.1.0.3
7f280bee4000  4K rw--- libgc.so.1.0.3
7f280bee5000264K rw---   [ anon ]
7f280bf2c000548K r-x-- ld-musl-x86_64.so.1
7f280bfbc000   1472K rw---   [ anon ]
7f280c12c000  4K r--s- localtime
7f280c12f000  8K -   [ anon ]
7f280c131000 84K rw---   [ anon ]
7f280c146000  8K -   [ anon ]
7f280c148000 84K rw---   [ anon ]
7f280c15d000  8K -   [ anon ]
7f280c15f000340K rw---   [ anon ]
7f280c1b4000  4K r ld-musl-x86_64.so.1
7f280c1b5000  4K rw--- ld-musl-x86_64.so.1
7f280c1b6000 12K rw---   [ anon ]
7ffdf4ad5000132K rw---   [ pila ]
7ffdf4b9c000  8K r   [ anon ]
7ffdf4b9e000  8K r-x--   [ anon ]
ff60  4K r-x--   [ anon ]
 total89624K


versus 0.17.2 


sudo pmap 26094
26094:   httpasync/src/httpasync
55b617f37000104K r-x-- httpasync
55b61815  4K r httpasync
55b618151000  4K rw--- httpasync
55b618152000 28K rw---   [ anon ]
55b6194e120K rw---   [ anon ]
7fe5853e4000  11648K rw---   [ anon ]
7fe585f44000   2172K r-x-- libgc.so.1.0.3
7fe586163000  4K r libgc.so.1.0.3
7fe586164000  4K rw--- libgc.so.1.0.3
7fe586165000264K rw---   [ anon ]
7fe5861ac000548K r-x-- ld-musl-x86_64.so.1
7fe586235000   1512K rw---   [ anon ]
7fe5863af000  8K -   [ anon ]
7fe5863b1000 84K rw---   [ anon ]
7fe5863c6000  8K -   [ anon ]
7fe5863c8000 84K rw---   [ anon ]
7fe5863dd000  8K -   [ anon ]
7fe5863df000340K rw---   [ anon ]
7fe586434000  4K r ld-musl-x86_64.so.1
7fe586435000  4K rw--- ld-musl-x86_64.so.1
7fe586436000 12K rw---   [ anon ]
7ffebaff6000132K rw---   [ pila ]
7ffebb124000  8K r   [ anon ]
7ffebb126000  8K r-x--   [ anon ]
ff60  4K r-x--   [ anon ]
 total17116K


Anyway, I understand that it should work (leak) in a similar way regardless of 
the gc or nim version used. There is a fixed number of clients that are 
connecting, so that sequence will grow to 1000 and stop there. I am measuring 
memory use after all clients (1000) have sent and received 1000 messages, so it 
should not depend on the speed they are added.

jcosborn, I have been doing all tests with "official" docker images 
(nimlang/nim:0.xx.y-alpine), and nimlang/nim:devel reports version 0.15.3. I 
have been looking for the original Dockerfile of those images to build an 
updated devel branch but it seems it is actually generated with nim code in a 
very smart way  I'll put some time on this and report back.


Re: How to count varargs[untyped] inside of template?

2018-04-03 Thread cabhishek
@r3d9u11 I don't think you can do that with a template. More information here 
[https://nim-lang.org/docs/manual.html#templates-varargs-of-untyped](https://nim-lang.org/docs/manual.html#templates-varargs-of-untyped).