370 karma · joined Oct 11, 2016 (10y ago) · 36 submissions
[ my public key: https://keybase.io/414owen; my proof: https://keybase.io/414owen/sigs/QGb2QrkyTUSMzBiHib_rL_aoACN-NGtHJHQ8RmxQguY ]
1.
A faster bump allocator for rust(owen.cafe ↗)
6 points · by 414owen · 5mo ago · discuss
2.
A faster bump allocator for rust(owen.cafe ↗)
6 points · by 414owen · 5mo ago · discuss
comment 11mo ago · link · parent
It sounds like subtraction over Nats needs to be split into `sub?`, and `sub!`, the former returning an option, and the latter crashing, on underflow, as is the Lean convention?
To use the default `sub`, you should need to provide a witness that the minuend is >= the subtrahend...
The version with silent underflow is still useful, it should just be called `saturatingSub`, or something, so that mathematicians using it know what they're getting themselves into...
7.
Speeding up tree-sitter-haskell 50x(owen.cafe ↗)
8 points · by 414owen · 3y ago · 1 comment
comment 3y ago · link · parent
It's not a useful architecture, but it teaches the thought process really well, and you end up discovering a lot of optimization naturally.
For this article, I'm measuring every step to see what the performance implications of the changes are, which, along with some educated guesses and some googling/reading other articles, was enough for me to figure out what was going on.
In part two (https://owen.cafe/posts/the-same-speed-as-c/) especially, I didn't know what was going on with the benchmarks for a long time. Eventually I got lucky and made a change, which led to a hypothesis, which lead to more tests, which led to a conclusion.
comment 3y ago · link · parent
https://owen.cafe/posts/the-same-speed-as-c/
But taking the length of the string as a parameter is not, because that changes the problem statement (making the solution vectorizable)
Also note that you'll try to read element -1 of the input. You probably want to change the `>=` to a `>`
comment 3y ago · link · parent
I would suggest the latter is what you want most of the time.
There's also the option of running a quick check for the null terminator before the loop, and then optimizing the loop for the other options.
But in any case, I think the demonstration of the technique of rearranging branches is interesting, and I needed a program to apply it to.
comment 3y ago · link · parent
I might be missing a reason that this information of opaque to the compiler though, in which case, this section of the article is indeed lacking, but I'm happy to learn :)
comment 3y ago · link · parent
On my machine I'm getting 0.244s for `loop-5.x64.s` and 0.422s for your implementation above.
I'm not sure why exactly we're seeing this discrepancy, and for what it's worth your implementation looks faster to me. I guess this is why you need to always benchmark on the hardware you're going to be running the code on...
comment 3y ago · link · parent
https://owen.cafe/posts/the-same-speed-as-c/
And as others have pointed out, you can tweak the input, then vectorize the algo, if you want to go that route.
I considered this a pedagogical exercise and I sincerely hope nobody will start dropping down to assembly without a very good reason to.
comment 3y ago · link · parent
It achieves 3.88GiB/s
I intentionally didn't go down the route of vectorizing. I wanted to keep the scope of the problem small, and show off the assembly tips and tricks in the post, but maybe there's potential for a future post, where I pad the input string and vectorize the algorithm :)
comment 3y ago · link · parent
So, the maximum amount of times you can hit '\0' is once in the string, because then the function returns, but you can hit the other characters many times, which seems to be information a compiler has access to without PGO.
PGO does help, of course, and on my machine gives me 2.80s, which is better than the code at the end of the `Rearranging blocks` section :)
> I assume that their test input (which isn't described in the post, and is also not in their GitHub repo)
It's described under `Benchmarking setup`, and is in the repository here: https://github.com/414owen/blog-code/blob/master/01-six-time...
Side note: There's a part two to this post (linked at the bottom) where I make the C code as fast as I possibly can, and it beats all the assembly in this post.
I never said writing assembly is (necessarily) a good idea, I just find optimizing it, and deciphering compiler output, an interesting challenge, and a good learning opportunity.
comment 3y ago · link · parent
That said, passion and curiosity win out in the long run.
If you build a POC without the right expertise you might find the product needs rewriting from scratch pretty soon. That might be fine though.
22.
{n} times faster than C(owen.cafe ↗)
447 points · by 414owen · 3y ago · 237 comments
comment 4y ago · link · parent
Lemon produces this report for my grammar:
Parser statistics:
terminal symbols................... 19
non-terminal symbols............... 42
total symbols...................... 61
rules.............................. 75
states............................. 56
conflicts.......................... 0
action table entries............... 377
lookahead table entries............ 379
total table size (bytes)........... 1433
It generates a parser that seems to be a reasonable size: $ wc src/parser.c
2200 10090 78282 src/parser.c
I've tried a few other parser generators, lemon was my favourite.re2c for tokenizing, and lemon for parsing =
comment 4y ago · link · parent
No need to map header (or other) files to C files. Tup detects when files are read and adds them as implicit dependencies.
Environment variables (that are used) are considered build inputs, so no need to `make clean` when you need a build with debug symbols.
---
Admittedly my project is quite straightforward, but I thoroughly recommend giving Tup a try.
comment 4y ago · link · parent
I'm personally far more productive in Haskell than in any other language I've tried. I don't know what's the Right Way, but it's the Best Way I've found so far.
comment 4y ago · link · parent
I actually posted https://select.pink/ to HN ages ago, but it died in `new`: https://news.ycombinator.com/item?id=24959045
OP's game has some nice features. The timing is neat, and to be honest I didn't even consider using the source as the visualization.
comment 4y ago · link · parent
Mine displays the elements as nested blocks, instead of printing a tree.
comment 5y ago · link · parent
> the asynchronous communication between the renderer and the extension-host severely limits how fast bracket pair colorization can be when implemented as an extension. This limit cannot be overcome
Nope, I'm not convinced. If it can be done internally, then you should expose more internals until it's possible to do it with the public API.
I bet this could be made really performant if vscode had incremental parsing, like tree-sitter+Atom.