Monday, March 27, 2023

Rust

I've just recently completed an online course for Rust. I find Rust a very interesting language. I've always subscribed to the philosophy that the compiler should try as hard as possible to find errors for you. While I can appreciate an interpreted language like Python, in my experience Python requires an enormous amount of discipline to write a large Python program with many team members. In a language like Java, the compiler is doing so much tedious work by making sure you don't pass arguments or assign variables of the wrong type.

The interesting thing about Rust is that it doesn't have a garbage collector. Rust is a replacement for system languages like C or C++, where it is not always possible or desirable to have a garbage collector thread working away int he background.

While I'm not the best at C++, I have used it enough to realize that managing memory consumes a big chunk of mental overhead. I know about patterns like using the stack to free resources and I know all about memory pools, but I don't feel comfortable enough with C++ to say that I've fully assimilated all the patterns good C++ programmers use to keep themselves out of trouble. Rust is a window on that world.

Whenever you find people using a (good) pattern, other people will try to make a computer language that accommodates it. Using a stack while in assembly leads to things like procedures. The judicious use of goto leads to things like the break or return statement. Even recently, a style of programming that tries to make everything immutable leads to a type of programming called functional programing. Rust tells me about the types of patterns C++ programmers use to keep themselves from making mistakes.

Rust has this thing called the borrow checker. It's primary purpose it to make sure that only one chunk of code owns a variable or piece of memory. Without a garbage collector, every object must be manually freed exactly once. This functionally means that every object has an owner who's job it is to manage the lifetime of the object and free it when it's not used anymore.

The borrow checker essentially forces you to make clear which functions are merely using an object and which function owns the object. It works surprisingly well although I've heard complaints that for things like a tree structure with a parent back links you have to do some serious thinking to make it all work. Honestly, I remember writing a doubly linked list in C++ and felt it was like watching bender putting on his own arms.

In any case, I hope I have the privilege of working on a Rust code base at some point. At the very least it will make me a better C++ programmer.

Wednesday, February 22, 2023

Gave up on using a Ryzen 9 5950X with a B450 MSI Tomahawk motherboard - too unstable

 So after much time and effort trying to stabilize the Ryzen 9 5950X with the B450 Tomahawk, I gave up and just got a B550 Tomahawk motherboard. All the things that should have worked on the B450 motherboard now work on the B550 motherboard. Specifically, you can run it at default "auto" BPO settings. You can run it with PBO enabled. You can run the ram at the XMP-1 and XMP-2 profiles (3200Mhz). I can even max out the system's cooling at hit 90C on the processor. Nice.

So what went wrong with the B450? No idea. It's probably power/VRM related but it could also easily be electrical interference related as well. All I know is it it kept giving me the same error: black screen and it needed to be reset at the power supply switch because holding down the power on button didn't work.

Fun facts, if you run the 5950X with PBO explicitly disabled AND you set the ram to 2133Mhz, it runs reasonably stable but will sometimes crash after a sleep. Increasing the RAM bus speed or turning on PBO will make it more likely to crash. Weirdly setting the PBO power limits to the motherboard limits didn't seem to hurt stability that much. In fact there's a chance the stability was a little better. It makes intuitive sense at first glance but AFAIK the motherboard power limits are higher than if you simply disable PBO.. and setting higher limits should cause more instability.. so I'm a bit suspicious of my subjective stability experience.

Another interesting factoid involves the RAM compatibility list that MSI produces for that motherboard. Initially they didn't differentiate between the 5000 series and the rest but since then they've revised it so that the 5000 series had a different list with no ram listed as being compatible over 2666Mhz. Recently I can't even get MSI's website to produce a ram compatibility list for the 5000 series processors. I'm guessing this means MSI has noticed the board is flaky with 5000 series processors.

I'm putting this out there to save people a bit of time if they're having trouble with 5000 series Ryzen processors on the B450 Tomahawk board. You're not going to find stability nirvana with that board.

Wednesday, December 28, 2022

5950X B405 MSI Tomahawk crash caused by XMP?

Ok guys. Just a quick post here...

so I recently bought a 5950X for use on my B450 MSI Tomahawk motherboard. I figured everything should work ok. However, I've had multiple problems.

First problem was that the motherboard's default PBO setting (or "auto") seems to cause the machine to crash. I don't really know why since it should BE OFF BY DEFAULT but whatever. If you set the setting to disabled or configure PBO to use the motherboard defined power limits you'll be good to go.I don't really understand why this is. The motherboard is capable of supplying more power than the CPU needs but if you turn it on, or just leave it as "auto", the machine is unstable. Using motherboard power limits (which are very high) seems to work fine though. WTF?

The second more surprising problem is that enabling XMP with my super low latency memory causes random (if somewhat infrequent) crashes. What happens is the screen goes blank and the system won't respond to any attempts to reset. You have to turn off the power supply, wait a few seconds, then turn it back on. It's a nasty crash. This is also the symptom if PBO is set to auto, btw. Initially I thought this was power related since I was using a cheap 550W power supply. But upgrading to a 750W good power supply did nothing.

In any case the MSI Tomahawk website's supported memory list gives a clue as to what is happening here. The motherboard supports different memory depending on the generation. The Ryzen 5000 series only supports memory up to 2666Mhz speeds.. Which is weird.. but is a big clue that there's some issue with the motherbaord, the 5000 series and high speed memory.

In any case I'm now running my memory at 2666Mhz but with crazy low timings of 12-12-12-28 thanks to having 3200Mhz memory with 14-14-14-34 timings running at a lower bus speed. Memory timings are specified in clock cycles but the timings don't change with clock speed so the numbers can be brought down when the bus speed decreases. So far it's stable and it's been a while.

I'm putting this out there because it took a stupidly long amount of time to figure this out so hopefully it will show up if someone searches for it. The forums have some of this info but the forums also have a bad signal to noise ratio.


Wednesday, December 20, 2017

Quebec Monorail (moteur roue - moh tar rooo)

Philippe Couillard has proposed building a monorail from Montreal to Quebec to deal with traffic issues between the two cities. The proposal is to use Trensquebec's theoretical monorail idea to create a 250km/h overhead style monorail. I'm all for high speed rail links between cities, what puzzles me is how a crackpot idea got enough traction to end up being proposed by the premier of Quebec.

Many people seem to think of convention rail as being very slow. It certainly doesn't help that most of the experiences we have with rail involved waiting at rail crossings in our cars while an incredibly slow freight train passes by. The definition of conventional rails goes up to 200km/h for pre-exisitng track and 240km/h for new track. High speed rail is typically 300km/h. Even VIA rail trains, that aren't known for their speed, are going 150km/h. It's quite humbling when you're passed by a VIA train while driving along the 401.

The biggest problems with going fast on existing rails in North America is the entire system is setup and optimized for freight. The track quality is not great, the signaling is all setup for low speeds, the bends are tight, there's level crossings all over the place and the mile long freight trains inch by at 50km/h. There are so many freight trains that VIA will be unable to provide service in the near future as it will be too crowded to run passenger trains. All this is why VIA trains go at 150km/h instead of 200km/h.

The solution is new track. VIA has proposed a very inexpensive solution they call high frequency rail. The proposal creates a VIA dedicated line so that they can run their trains at 150km/h to +180km/h speeds with no random delays (like today) thanks to freight trains blocking the way. What people have noticed in europe is that the frequency of the trains and sticking to a schedule is more important to ridership than max speed. With VIA's proposal it gets that.

Then there's Trensquebec. The biggest issue with them is there's no technology. It's not a real project. There's not even a prototype train on prototype track. There's also their suspiciously low cost estimates (it should be higher than the high speed rail proposals) as well as their suspiciously high operating speed (I would estimate ~200km/h max if that). At this point I think it's a big con. Quebec should be teaming up with the federal government and private industry to back VIA's proposal.



Wednesday, November 29, 2017

Microsoft Edge

Mozilla has recently release Firefox Quantum. I supposed because it's supposed to be a quantum leap in web browser technology. Does this means that Scott Bakula will show up in your web browser at critical moments to help guide you through your web browsing experience? Nope. Sorry. It just means the Firefox has a brand new web engine that's been redesigned to similar to Chrome but better. If you haven't been taking Firefox seriously for a while now is the time to try it again. My experience has been great so far. Not only have I started to use Firefox again but it's now my web browser of choice.

Recently Windows went through one of those comically long updates and loaded the release notes for the update into Microsoft Edge web browser. Neat! I thought to myself. I haven't tried Microsoft's web browser in a long time and I know they've been working on it. If Firefox can improve so much maybe Edge can as well.

The first thing I noticed in Edge is that the scroll wheel on my mouse doesn't work. It seems to work everywhere else just not in Edge. How did they even do that? Well, I'm not going to debug that. Not now I have a Firefox that doesn't suck. Maybe I'll try Edge again in another 5 years or so. You know, when they've figured out how to get the mouse wheel scrolling work.

New information! It turns out that CatMouse was causing the problem. Windows 10 seems to ahev CatMouse like functionality built into it so removing it was now big deal.

Thursday, November 23, 2017

IPv6 adoption hits 20%

About 2 years ago I noticed that IPv6 adoption was at about 7%. Well now IPv6 adoption is at 20% and still growing quickly. 20% is excellent! One in five people on the internet have an IPv6 address. This is the year of IPv6.

I'm still a little hopeful that this will mean that p2p technology will become viable again, but it's hard to say for sure. Security is much more important than it once was. I've also been burnt by the criminally cavalier approach to security that most companies seem to have. I may trust my router (barely) but not anything else. As a result I haven't turned on IPv6 on my router because I don't trust that everything on my LAN will actually do the right thing in that scenario.

*sigh*

Security on desktop and laptop machines isn't too bad anymore. The Windows 10 and OS X will ask the user if a program wants to open a port. Additionally, modern OSes do try and minimize their attack surfaces by not listening for connections when not required. I just can't remember if I've done something silly like turned on file sharing with guest access and that will be shared on the open internet. It wouldn't be the first time I've made that mistake. One of these days I'll have the time to experiment and see if file sharing restricts itself to LAN addresses. Also, if we get an public IPv6, does the OS also give us a private LAN address as well so we can bind more sensitive services only to that.

Tuesday, November 21, 2017

Typescript is fun

I recently went from programming on Java for almost 20 years to programming exclusively in Typescript and I like it.

Typescript is a super set of Javascript. It is essentially a typing system built on top of Javascript and it works amazingly well. When I first started programming in it I expect it to be a dancing bear, and from one perspective it sort of is, but man does this bear dance.

The way to think about Typescript is it makes Javascript scale. It's not really trying to be its own language as much as a set of tools that allow you to take existing Javascript code and add some typing sanity onto it. What makes it work is a combination of crazy good type inference and a sort of strong duck typing. So if you have something like this:

interface Person {
 String name;
 int age;
}

interface Monkey {
 String name;
 int age;
}


you can do this:
Person p = new MonkeyInstance();

or this:

Person p = { name: "Steve", age: 12 };
Monkey m = p;

and it doesn't care. So long as the interfaces are compatible you can assign it and it's all good. Java can't do this because Java is tracking types at the byte code level. A monkey and person are two different types that just happen to have the same properties. For Typescript having the same properties is what defines a type.

(Java does allow this sort of assignment in an around about fashion with functions. For instance, you can pass any method that takes a value and returns a value to a method expecting a Function. But it only works with functions, not objects)

Typescript also implements an idea I've wanted to see implemented for a long time. Nullable as a type!

In Java, we've started to use "Optional" instead of null because it makes the optional nature of the value part of the type. But, what if the language did it for you? Well Typescript does. Basically, you can't do this:

Person p = null;

You have to express that p might be null like this:

Person | null p = null;

Trying to do this using Java syntax gets confusing but the idea is that p might be a Person or it might be a null. Like using Optional, it makes the compiler track that a value might be optional, but unlike optional it's built in. The same multi-type trick works with any types:

Person | Exception p = findPerson();

p might be an Exception type or a Person and you'd need to do some additional work to work out what p is.

You can append however many you want:

Person | Exception | null p = findPerson();

In java you can do this with exception catch blocks, but nowhere else:

try {
 stuff();
} catch (NullPointerException | IOExecption | SqlException ex) {
 // ...
}

Here's a video of the inventor of Typescript explaining how Typescript deals with null.