Compile time code optimization.

2024-03-23 Thread Nycto
Just thought I would follow up here. Since my ultimate goal was faster builds, I ultimately found that the biggest end-to-end improvements were to simply reduce the amount of code being generated. It’s a bit of a “no kidding” realization, but also a bit opaque at the same time. For example, thi

Compile time code optimization.

2023-11-12 Thread Nycto
Just to document my journey a bit, switching from `object` to `ref object` for all my compile time state management sped up my macros by around %57:

Compile time code optimization.

2023-11-12 Thread Nycto
I've got a project that makes heavy use of macros and build time code-gen. The build has slowed down by a few seconds, so I'm spending some time optimizing the bottlenecks. However, I'm struggling to create a mental model of what is slow within the VM. For example, [this change](https://github.

Alternative to closure iterator that works in JS

2023-01-03 Thread Nycto
I'm trying to create a `View` type that lazily applies a callback when iterating over a set of values. My current implementation uses an iterator closure, but those don't work in JS. I've tried to create a reduced example of what I'm trying to accomplish: type Database*[R] =

Discovery rules for the 'items' iterator

2022-02-13 Thread Nycto
I'm trying to figure out the compiler rules for how items are discovered. I've got some code that works when it's in a single file, but fails when spread across two files. Here is the working code: But when I take that same code and spread it across two file

Void as a type in a tuple

2022-02-06 Thread Nycto
It's an edge case of some macros I'm working on where the user could provide a void type -- I'm trying to determine if it is supportable. This works: proc foo(tup: void) = discard foo() Run So I was trying to see if there was an equivalent for tuples

Void as a type in a tuple

2022-02-06 Thread Nycto
> pointer is the equivalent of void* of C Do you have an example of how I would use this in practice?

Void as a type in a tuple

2022-02-06 Thread Nycto
Yes -- this all makes sense, but it doesn't help with my original question. If I've got a function signature like this, is it callable in any way? proc foo(tup: (string, void)) Run Using nil was obviously contrived, but this also doesn't work: foo(("bar",

Void as a type in a tuple

2022-02-06 Thread Nycto
> Nil is not void Yup -- I'm aware nil is not void. The example I provided does not compile. But it's the closest I could think of to provide a void value. > Are you trying for default or optional parameters? I'm working with codegen via macros. I'm trying to handle a situation where a user pr

Void as a type in a tuple

2022-02-06 Thread Nycto
Is there any way to instantiate a tuple where one of the values is `void`? For example: proc foo(tup: (string, void)) = discard foo(("foo", nil)) Run

Exclude from generated docs

2022-02-06 Thread Nycto
For anyone else searching, there is a feature request here:

Exclude from generated docs

2022-02-04 Thread Nycto
That would work for my contrived example, but not as a solution for my larger project, unfortunately. I've got my code spread out across multiple files, which means the methods have to stay public.

Exclude from generated docs

2022-02-04 Thread Nycto
Hmm. That doesn't seem to solve this problem. The documentation generator is running a full compile pass. So if I put code that is actually being used behind a `when not defined(nimdoc)` clause, the doc generator fails to compile. For example, trying to generate documentation for this:

Exclude from generated docs

2022-02-04 Thread Nycto
Is there any way to exclude some units of code from the generated docs? I’ve got some modules and objects that need to be public so the rest of my module can access them, but aren’t considered a public API. Package private, basically. I’m fine with leaving them as public, but I would like to pre

How to find bottlenecks?

2022-01-28 Thread Nycto
This guide gives you a few options:

Atomics: attempting to call undeclared routine: 'testAndSet'

2022-01-20 Thread Nycto
> Also please use threading/atomics instead. Thanks for the pointer, @planetis

Atomics: attempting to call undeclared routine: 'testAndSet'

2022-01-20 Thread Nycto
Yup, didn’t mean to trivialize the idea of lock free anything. My endgame here is a reduced feature set: * keys and values will always be ints * Open address hashing * get and set should be lock free * I’m going to try making ‘delete’ lock free using tombstoning * I need resizing, but I

Atomics: attempting to call undeclared routine: 'testAndSet'

2022-01-19 Thread Nycto
Follow up: I submitted a PR to fix this:

Atomics: attempting to call undeclared routine: 'testAndSet'

2022-01-19 Thread Nycto
> Here: > while location.guard.testAndSet(moAcquire): discard > It should > probably be rewritten > while testAndSet(location.guard, moAcquire) Yup -- you're right about this. Updating the file locally resolved the issue. > This can only be guaranteed if the value has up to the native machine si

Atomics: attempting to call undeclared routine: 'testAndSet'

2022-01-19 Thread Nycto
I started playing with the [atomics](https://nim-lang.org/docs/atomics.html) module this morning, but I hit a roadblock pretty quick. I've got two files in my project... a src file and a test file: # src/OpenAddrTable.nim import std/atomics type OpenAddrTab

Look up proc signature from an ident

2022-01-04 Thread Nycto
Awesome! Thank you I might be pressing my luck, but is it possible to do this with concepts, too? import macros macro examine(ident: typed) = echo ident.getImpl.repr # type Foo = concept f proc someProc(arg: Foo) = discard

Look up proc signature from an ident

2022-01-04 Thread Nycto
If I've got a macro where I pass an `ident` as an argument, is it possible to read the signature of the proc? Here is an example of what I'm trying to do: import macros macro examine(ident: untyped) = ident.expectKind(nnkIdent) # My goal is to read t