Here's a small update on programming related stuff.
I think pretty much every developer has heard about the "Tabs vs Spaces" debate before, which only shows one thing: Development tools are pretty bad. A good IDE should be able to just handle either encoding and display the indentation as the user desires.
Given that I recently decided to try out using an indentation width of 2 instead of 4 (and I've seen people use the widths 1,2,3,4 and 8), the encoding which makes the most sense to me is
That way the indentation is consistent, while just the display of tabs may change. But of course whenever more than one developer is involved, usually:
diff
is now useless or full of noiseI am often using (neo)vim, which, at least with my configuration, only fucks with the indentation. In comparison, IDEs not only fuck the indentation up, but they also tend to do """helpful""" formats like the following:
I think vim handles the indentation fine if I format the whole file;
but it does tend to insert the wrong characters (tabs for alignment)
when writing the line initially.
As I often forget to format the file completely,
one alternative would be to have a dedicated code formatter,
which you could automatically run on
the changed files before pushing a commit with git
[0].
Big downside: Tools like
clang-format
and Indent
require lots of configuring if you just want
it to do the indentation / alignment thingy.
I'm not even sure whether there was a tool which just
does that.
bcpp could fit the
bill, but I'm not sure from the description whether
it supports mixing these two properly.
So that's how I ended up with my weekend project cif
.
cif
just does the formatting and alignment for
C code.
It handles some things like strings, comments and preprocessor formatting,
but it will do its job wrong if you e.g. want to
open scopes using macros.
I setup a hotkey for vim and a hook for git
, so I'm all set [1].
Due to the Performance Aware Programming Course, I wanted to see whether I can speedup some memory allocations. The results were mixed and I'm annoyed.
Good news: There was some real low hanging fruit.
During the initialization of the threads,
I allocate a lot of memory, because the pages on linux
are only mapped to physical memory once
the pages are written to once.
But I did a whoopsie and called ArenaAllocateZero
instead of ArenaAllocate
in my code on big buffers
of memory.
While this helps with tracking down uninitilized memory bugs,
it's a waste of work (assuming that my program is written correctly).
Not doing that speeds up the generator by ~50-100ms.
So it's not really a big concern, but
now this website is generated in ~15ms (when in cache),
which is pretty awesome.
The other "quick" thing I wanted to test was using
larger (memory) pages.
Given the time scale I am working with,
I thought that generating less page faults might be
beneficial,
especially because linux, in contrast to Windows,
doesn't require elevated privileges to use large pages.
Or so I thought.
After adding MAP_HUGETLB
and MAP_HUGE_2MB
to the arguments
passed into my mmap
call, my memory allocation failed.
From what I gathered, it seems like you need to pass some additional
flags to the kernel on boot such that these larger pages are actually
allocated [2].
I also want to look into getting rid
of memory-mapped files and replacing
them with good ol' read
calls.
However, that change would require a bunch more adjustments to my code,
so that will have to wait.
I found and fixed some multi-threading bugs (static
variables are not thread-safe, whoopsie).
Personal websites are still building within ~15ms (when in cache),
while the test site with 20k posts now builds within 600ms (when in cache).
Pretty happy about that.
I'm working on a matrix client with a friend. Progress has been slow because most of the work is either juggling some C# bullshit or figuring out the various steps and formats which matrix expects. So far we have:
libOlm
library, create an account
with public/private (and onetime / recovery) keyslibOlm
is actually somewhat nice to use)sync
request to retrieve a mapping from users to room IDsBut this all is written in a "sandbox"-y / fucking around kind of way, meaning we don't even have a window open yet. I hope once we manage to send + receive encrypted text messages that we can actually turn this experiment into something somewhat usable.
Additionally, given my recent usage of Neovide, I dig the smooth animations but I'm hitting more shortcomings of neovim. While these probably could be fixed with more plugins / an LSP / ..., I'm kind of tempted to roll my own text editor for C programming. At least my short list of requirements seems somewhat reasonable, if I am able to get OpenGL to cooperate:
And I still need to work on my C debugger. Probably some update of GCC shuffled some debug information around, which lead to me needing to fix the hardcoded values of the debugger. It would be really badass if I am able to get it into a usable state. But hey, I managed to recod a little demo video which I'm gonna put / link to on my resume, so that's gotta be worth something.
[0]: Sounds super easy in theory, figuring out how to make this work in practice is a bit rough. I still need to put this onto my cheat sheet for git.
[1]: My hook actually creates a copy of the files before running the formatter on them. I want to battle-test it a bit more to avoid losing all of my changes due to some weird bugs. But to be fair, this is just my being paranoid. At worst, my formatter fucked the indentation up, but it never made semantic changes to my code.
[2]: I did confirm that my linux installation + CPU supports large parges. It's just that none are available:
> cat /proc/meminfo
...
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
...
>:(