 I've heard so much about this conference over the years and I'm glad I can make it. So this is where you can get in touch with me if you have any questions about the talk later on. So Crystal itself, I've been a contributor to the language for a little over a year and I wrote Postgres driver for it because Postgres is pretty cool. But so what is Crystal? It is a very Ruby inspired language and so if you come to it as a Rubyist you'll feel right at home but it's compiled and it's compiled with the toolchain called LLVM which powers a lot of the Apple ecosystem, also PlayStation and some others and I think that's really important because all of the advances that go into LLVM, if you use an LLVM language such as Crystal, Rust, Swift you get all of that advancements yourself too and so a lot of the speed that Crystal has is due to the language itself but a lot of it is due to all the optimizations that go into LLVM over the last 10 or so years that LLVM's been around. It's entirely self-hosted and so that means that the lexer, the parser, the compiler, the standard library all is in Crystal itself so it's really easy to go in and you know contribute to the language, see how things are done and even more importantly when you write your own code the optimizations can go from your code to the standard library and it can, there's no like barrier there that if you have a standard library and see in your things in Ruby there's sort of a barrier between the optimizations that can happen. The main difference though is that it is statically typed in a static dispatch and you might think okay well that can't be very Ruby like but as you will go on to see when I show some examples that you can still feel like Ruby because a lot of the times there's type inference you don't have to say the types and because it has a pretty unique way of doing unions of types if your method returns two different types or more it creates a union of those types and so you can it still feels like there's duck typing it still feels very at home and it is very fast and this just to get you know a little excited Crystal here's on the left Ruby's on the right and you can see you know the Kamal framework is a lot like Sinatra this it looks very similar but if you run it through you know a benchmark here you can see that it's an order magnitude faster in order to magnitude more requests per second and two orders of magnitude less RAM now you know micro benchmarks aside you know you take those with a grain of salt but it shows that there's you know even for your regular code you can probably see some good improvements and don't take my word for it sidekick author Mike Herman three days after coming to language for the first time was able to make a minimum viable like sidekick implementation and then after finishing it you saw you know maybe five to ten next improvements on some of the things he was doing so what are the similarities it has object oriented stuff it has blocks much of the standard library that used to in Ruby like this this code works the same as it does in Ruby and Crystal and this is compiling and running it here on the right so this is all you know very much the same it even has a spec framework which is pretty cool that it won't do the syntax coloring correctly in the thing but you know you can have some nice specs that built-in so you can feel right at home but let's get into you know some more of the differences of what makes us it's not a different language instead of just being a compiled Ruby this this code here has you know pretty much the same as Ruby except you can see the the property part up here is its property instead of adder accessor and there's a little bit of a type annotation there but one of the nice things you can do in Crystal here is if you put in at signs up top you don't need to do the it sort of does the common thing of putting something in an instance variable it does that for you which is it's not that's not a huge thing but it is nice and takes down a little bit of some boilerplate you can see here it works just like OOP one of the things I like the most though is this fancier to proc and see an array here and you know we can use upcase you'll notice here that it's a period instead of a colon and that's very I think a lot of the speed comes from that because if you print it out it's only half the amount of ink but what is actually useful is you can you can chain the methods there you don't have to if you want to do a couple things you don't have to go out to the bigger blocks and texts and you can even call methods on it and sort of and do things like that so for little simple things you know it's just it you know it's again this is a small thing but it's I think it's a nice improvement but the big difference is the type system and how this is actually statically type language now I mentioned before that aesthetic dispatch and that means at runtime it doesn't have to go looking for a method chain to look where to call this is that's all done at compile time and the way that actually works is that this this function here that double the runs multiply to it actually makes two different methods and so you can see here that the compile time type it's known that it's going to be int and string and this is done at compile time but the union the union types is what actually makes it be able to have a typed language but still feel nice and so we have a little method here that if the number is greater than 10 it returns the number otherwise it returns the string too low as a very bad validation method and if so if you pass in 15 we get the answer 15 back if we pass in the a string called low or number one then we get too low coming we get too low coming back the runtime type is int and string but the compile type you see it's a union of int and string and so what does that mean if we run multiplied by two on it on the results that all works fine we get 30 we get the string repeated but if we try and add do plus we're going to get a problem with the the method and that's because while strings do have the plus method they don't have it with an integer they have it with they have it with a character and they have it with another string so if we try and do a naive thing and go up here and remove these two lines and now we're just returning it or no now the thing that used to work fails to work because there's no method multiply for nil and Ruby see this all the time at runtime was saying you know undefined method on no here this is being caught at compile time and there's no special nil checking this is just falling out of the fact that we're creating a union of int and no the other kind of thing that's nice if you have these type annotations normally you don't have to say them but in Ruby in library code especially you see things like there's a little bit over rod example but you see things like this where you're switching on the types as you come in and you have to do that every time the methods run you know over and over again and it gets you know it's a little ugly but if you want to say the types in crystal you can then break out the methods and do overloading and this provides you know a little bit of a nicer interface where you can still have have a nice you know function calls but have it be fast and not be doing all that type checking it at runtime we're not going to get too much into the macros but one thing that's nice is that this is how you can still have you know some adder adder readers adder writers and such my favorite one here is the pretty print one because it takes the the the the the code that you have and puts that in there and so if you're doing like some puts debugging you know it's nice to know exactly where it is instead of having to add little annotations everywhere and this is just a real quick example of how if you were going to do macros so instead of add a reader or adder accessor it's getter inside crystal and this is how it's defined with sort of just like a you know erb thing but for your code which is it's really easy to to write these yourself so when i first did the Postgres driver i did it linking against the libpq which is the Postgres client library and these 10 lines here is actually all you need to link against a C library pull up the couple functions that you want and then connect to the database here and issue a query and you can see here this is actually you know a live thing and it's running a query against my local Postgres that's running and like the fact that you can link against something with this just this little amount of code is really powerful especially for a language that's new like crystal because there's not all that too many libraries and being able to lean on all the you know vast array of C libraries and do it very easily is nice and just as one last thing one difference between crystal structs and Ruby structs is that in crystal they they look to be the same but instead it's a difference of if they're allocated on the stack of the heap and when it's a class it's it's over on the heap and that has to be garbage collected but it works as you'd expect if you make it a struct it then you can't change the values in it in runtime you see like I tried to call change name and it didn't actually work but the advantage is it's on the just on the stack and there doesn't be garbage collected and so if you have a lot of small things you're making if you make it structs it makes your program like way faster because it's not doesn't have put any pressure on the GC and then just as a final thing one one way that you get a lot of speed in crystal is that all of the methods that do to us or your string interpolation in the middle actually gets rewritten at compile time to be IO objects and so that way it's not allocating lots of little strings and then can get in together with more strings like it still feels like you're doing in Ruby but it's just all putting it into a buffer and so it's really fast and I guess I had one last thing and so a lot of people ask about concurrency and it this one they've leaned very heavily on like the go community of coroutines and channels and so if you're familiar with that method it's the same and that's all I have thank you very much if you're interested in trying it