Small introductory post about ARC/ORC in Nim.

2020-10-14 Thread cdunn2001
Interesting. This helps me understand what's going on. I was a big fan of "owned refs", but I didn't follow the discussion last year. I wanted to wait for the feature to becom

RLock compilation failure

2020-10-14 Thread o24
This is my first few hours working with Nim. On my Debian machine with Linux 5.7, the following Nim file compiles successfully: import rlocks var x: RLock x.initRLock() echo $tryAcquire(x) # prints out "true" Run but the following fails to compile:

A nice read about Nim (blog article)

2020-10-14 Thread timothee
see also: [[performance] performance tricks to improve std/json, parsers, lookups · Issue #188 · nim-lang/RFCs]()

Small introductory post about ARC/ORC in Nim.

2020-10-14 Thread Yardanico
Pulled the articles down for a bit, so we can get a proper guest article on the Nim blog, and then share that on HN/Reddit/etc

Issue creating json nodes

2020-10-14 Thread tinygiant
Awesome, it worked! Thanks for your time!

A nice read about Nim (blog article)

2020-10-14 Thread Araq
> So, this kostya benchmark seems to me like a textbook case of what not to use > json for (500k*3 floats...Really?). Yeah, this benchmark is terrible bullshit but our JSON parser is slow. My "packedjson" package helps with the memory consumption of the lame "let's read it all into a graph stru

A nice read about Nim (blog article)

2020-10-14 Thread cblake
So, this kostya benchmark seems to me like a textbook case of what _not_ to use json for (500k*3 floats...Really?). Any pure binary protocol would be better, even if you had to byte swap for endianness portability. First I ran it and it was lke 25% system time (reading a file out of a /dev/shm m

Issue creating json nodes

2020-10-14 Thread Yardanico
Hello! Your problem comes from the fact that JsonNode is a "ref object", so you're actually adding the same JsonNode and modifying it each time in the loop, that's why you get all duplicates (they refer to the same value). To fix it, you can for example create your node in the loop itself:

Issue creating json nodes

2020-10-14 Thread tinygiant
New to nim and trying to create some json nodes with very little luck. Here's what I have so far (`areas` is just alist of strings). The end result needs to be a set of json nodes that will be added as subnodes to another json node. I need to create a group of nodes that look just like `areaJson

python dict implementation for Nim's Table

2020-10-14 Thread cblake
`lptabz` is more or less drop-in compatible with both sets & tables (both ordered & unordered) and maybe more explicitly states up front that it is a multiset/multitable which has caused quite a bit of confusion/surprise (What!??! Dups in a hash?! The heck you say! Take it out!! They are now de

Non-blocking async HTTP server

2020-10-14 Thread shirleyquirk
using `waitFor` blocks, so only do that if you want to block, otherwise hold onto the `Future` returned by `server.serve` template handle_server_error()= let e = getCurrentException() echo "Something went wrong." & e.msg server.close() var server_futu

A nice read about Nim (blog article)

2020-10-14 Thread bpr
One of the claimed downsides of Python the article mentions is The design of the language, which puts the indentation as the factor to define the code block’s formatting, is considered a downside by many. If you come from other traditional languages, it can be hard to adapt

Non-blocking async HTTP server

2020-10-14 Thread ElAfalw
This is my code (but it obviously blocks everything). var server = newAsyncHttpServer() proc handler(req: Request) {.async,gcsafe.} = #...do some stuff await req.respond(status.HttpCode, body, headers) try: echo ":: Starting server on port " &

Any lib to control the keyboard?

2020-10-14 Thread shirleyquirk
illwill is brilliant! you should submit that snippet to rosetta, i'd only set it to not fullscreen: illwillIInit(fullscreen=false) Run

python dict implementation for Nim's Table

2020-10-14 Thread slonik_az
> A simple way to improve this by 2x is in `lptabz` which is to store some of > the hash code along with the index in the "hash-table-like part". Then if the > hash table part uses linear probing this reduces to just 2 loads. This is 2x > more than the 1 load "unordered" variant, but you get com

Small introductory post about ARC/ORC in Nim.

2020-10-14 Thread Yardanico
Thanks a lot for your feedback :) I'm planning to post it on \- both the original English version and a translation to Russian, since habr.com is the most popular Russian IT/tech-related website with user-made articles.

Small introductory post about ARC/ORC in Nim.

2020-10-14 Thread Araq
I love it. Very good job! Maybe I would phrase a couple of things differently, but everything seems to be correct. (And that's rare!)

python dict implementation for Nim's Table

2020-10-14 Thread cblake
Oh, and in the [adix](https://github.com/c-blake/adix) git history, I do have a pseudo-random probing impl along with one that has an idea by @timothee to start linear probing and only switch to pseudo-random after some number of cache lines. Those used to be called `otset.nim` and `ottab.nim` a

Small introductory post about ARC/ORC in Nim.

2020-10-14 Thread Yardanico
Hello, just wanted to share my post on dev.to which is kind of an overview of ARC/ORC. I don't have experience writing posts like that, so please point out to errors if you find any :) I think that one of the ways to promote Nim is to write posts like that on different websites (habr, medium, de

Nimble path and local packages list

2020-10-14 Thread shashlick
Nimble caches the package list locally in $nimbleDir. That's why you see `/home/user/.nimble/packages_localpackges.json`. See [here](https://github.com/nim-lang/nimble/blob/f4c818a046c2c3ceb1523c4c974e4b6e625d8ca3/src/nimblepkg/packageinfo.nim#L179). You can verify that this file is a copy of th

python dict implementation for Nim's Table

2020-10-14 Thread cblake
The performance regression in question was a known and not mysterious very temporary fix until the weak integer hash function was replaced with a stronger one (the original problem). In that sense, a complaint of a performance regression across that commit is a red herring for anything _except_

python dict implementation for Nim's Table

2020-10-14 Thread slonik_az
There has been recent complains that run-time performance of Nim's Table implementation got worse: I am curious, whether anyone tried to implement Python 3.6+ `dict` algorithm in

Redirect stdout for certain execution

2020-10-14 Thread AyJayKay
Maybe they should even be called `duplicateFileHandle(handle)` and `assignFileHandle(source, target)`. I made a helper for my project now that can do `setStdout(file)` and `resetStdout()`. And same for std error and input. (I like descriptive names and simple interfaces :D )

How to gracefully terminate an asynchttpserver with Ctrl-C?

2020-10-14 Thread mrhdias
After doing some research I get an idea of how AsyncEvent works. But, where to place the setControlCHook function without getting the previous error message on compilation? import os, asyncdispatch, threadpool proc asyncTest(): Future[string] = let event = newAsyncEv

Nimble path and local packages list

2020-10-14 Thread Clonk
Hi, I'm trying to add packages to nimble. According to the`readme <[https://github.com/nim-lang/nimble#nimble-path>`](https://github.com/nim-lang/nimble#nimble-path>`)_ , having a config file located in `/home/user/.config/nimble/nimble.ini` such as : [PackageList] name=Loca

Any lib to control the keyboard?

2020-10-14 Thread pietroppeter
I was going to check if @shirleyquirk version worked on windows and try to port Python example from rosetta code to nim... but then I realized that [illwill](https://github.com/johnnovak/illwill) possibly provides the functionality you are looking for and more: Adapted from illwil readme, works

A nice read about Nim (blog article)

2020-10-14 Thread hugogranstrom
Probably something else that's limiting as well, but what about putting the CT/RT object definitions in a `when nimvm: ### else: ###`?

A nice read about Nim (blog article)

2020-10-14 Thread Araq
> Compile-time is not a problem, use when nimvm Ha! Good one. (I'm aware, `when nimvm` doesn't help me as you cannot use it inside an object declaration.)

A nice read about Nim (blog article)

2020-10-14 Thread mratsim
Compile-time is not a problem, use `when nimvm` It's a bit annoying that `when nimvm` requires an else branch and can only have 2 branches but this is what I use to have bigints in the VM and fast implementation (even assembly or intrinsics) at runtime:

Any lib to control the keyboard?

2020-10-14 Thread Cleverson
thanks Shirley, much apreciated.

A nice read about Nim (blog article)

2020-10-14 Thread Araq
Last time I looked into json parsing performance I was blocked by our (silly IMO) requirements that json parsing must be do-able at compile-time... But please @cblake take a look, it's the most obvious candidate for optimizations.

A nice read about Nim (blog article)

2020-10-14 Thread cblake
Automatic detection of performance regressions might be nice, but has non-trivial implementation complexity. Besides naive or bad benchmarks or performance tests sometimes being worse than none at all, many CIs run on heavily shared computers. Such sharing makes real time passage a metric with

Any lib to control the keyboard?

2020-10-14 Thread shirleyquirk
import terminal proc getch_nonblock():char = when defined(windows): let fd = getStdHandle(STD_INPUT_HANDLE) var keyEvent = KEY_EVENT_RECORD() var numRead: cint doAssert(waitForSingleObject(fd, INFINITE) == WAIT_OBJECT_0) doAssert(readConsoleInp

How to gracefully terminate an asynchttpserver with Ctrl-C?

2020-10-14 Thread mrhdias
I'm trying to compile this example. But it fails to compile. What's wrong? import asyncdispatch let event = newAsyncEvent() event.addEvent(proc() = echo "test") event.trigger() Run Compiler error: test.nim(4, 6) Error: type mismatch: got

Show and tell: RPC on embedded devices

2020-10-14 Thread Clonk
> > I have no idea if we should simply introduce new APIs instead of emulating > > the old ones. I think it's a good idea; memory management is evolving with 1.4, so now is the good time to introduce gcs API changes. IMHO, It would clarify things, because calling a `GC_disableMarkAndSweep` on A

A nice read about Nim (blog article)

2020-10-14 Thread whiterock
You might wanna have a look at the crazy SIMD stuff Lemire is doing for parsing JSON: Here is also a video where he outlines some of the desing decisions: /

A nice read about Nim (blog article)

2020-10-14 Thread mratsim
We need to improve the JSON parser ...

A nice read about Nim (blog article)

2020-10-14 Thread xbello
I get this: real0m7,568s # -d:danger -d:lto real0m7,592s # -d:danger --verbosity:0 --opt:speed --hints:off real0m7,598s # -d:danger real0m8,285s # -d:danger --gc:orc real0m8,381s # -d:danger --gc:arc Run

Show and tell: RPC on embedded devices

2020-10-14 Thread Araq
> It's correct that the ORC cycle collector will only run at/on GC ref/decr's? Correct. And only on decrefs that are not decrefs to zero. But you can also disable it via `GC_disableMarkAndSweep` and run `GC_fullcollect` when you know you can afford it. These operations are now poorly named, the

Running a simple example based on the `httpbeast 0.2.2` framework made an error

2020-10-14 Thread lihf8515
Note: When i use browser request, there is no error, but when i use `wrk -c100-d20--latency http://192.12.1.1:8080/` for stress test, there is an error.

Running a simple example based on the `httpbeast 0.2.2` framework made an error

2020-10-14 Thread lihf8515
Running a simple example based on the `httpbeast 0.2.2` framework made an error :`getData.headersFinished` Selector not ready to send.[AssertionDefect]. My code is as follows: import segfaults import random import options, asyncdispatch import httpbeast

Nim Source Magic

2020-10-14 Thread Araq
I don't see how that would help. But then I don't see why compiler builtins are confusing either. It's not turtles all the way down, there is a ground floor.