117 points · by ksec · 2y ago · 78 comments
What's the state of Windows support.
How did the compiler speed drama unfold?
https://github.com/crystal-lang/crystal/issues/5430
> UPDATE 2023-04-24:
> All the main platform features for Windows are finished!
> There are still some smaller stories pending. Project board: https://github.com/orgs/crystal-lang/projects/11/views/5
> You can support the ongoing development financially: Windows suppport (https://opencollective.com/crystal-lang/projects/windows-sup...) project on Open Collective.
I don't think it's disproportionate. Windows is a huge platform with lots of developers. Also you don't hear anyone asking for other OS support because all other major operating systems are supported. So there's no real comparison.
The same thing was happening with Bun, and yet I've met lots of Windows developers who hate JavaScript.
I'll enjoy my time here when I can get it.
Which companies use Crystal in anger / production in front of real users?
Mentioned in the crystal conf talk held by a Kagi Developer
Also, >300 MB of RAM usage (in docker. Some might be the system) with only 2 users after running for a while seems a bit too much
https://crystal-lang.org/reference/1.11/guides/concurrency.h...
# A very basic HTTP server
require "http/server"
server = HTTP::Server.new do |context|
context.response.content_type = "text/plain"
context.response.print "Hello world, got #{context.request.path}!"
end
puts "Listening on http://127.0.0.1:8080"
server.listen(8080)
Nicely concise!This would be the Python equivalent:
# A very basic HTTP server
from http.server import BaseHTTPRequestHandler, HTTPServer
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(bytes(f"Hello world, got {self.path}!", 'utf8'))
httpd = HTTPServer(('', 8080), RequestHandler)
print("Listening on http://127.0.0.1:8080")
httpd.serve_forever()
Would like to see it in more languages. {-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Handler.Warp (run)
app :: Application
app request respond = do
respond $
responseLBS
status200
[("Content-Type", "text/plain")]
("Hello world, got" <> rawPathInfo request <> "!")
main :: IO ()
main = do
putStrLn "Listening on http://127.0.0.1:8080"
run 8080 app proc webServer {chan addr port} {
while {[gets $chan] ne ""} {}
puts $chan "HTTP/1.1 200 OK\n Connection: close\nContent-Type: text/plain\n"
puts $chan "Hello World!"
close $chan
}
socket -server webServer 8080
vwait forever 1: The comment
2: Printing the status message ("Listening on ...")
3: Outputting "Hello world, got {request.path}!"
Aka http request parsing and string extrapolation.https://crystal-lang.org/reference/1.11/index.html
I couldn't quite determine the reason of being of the Crystal language. Could someone with experience with the language explain what is its appeal, and why it would be worth trying/learning?
Thanks!
Thank you!
I think the Achilles heel for Crystal is its compilation time on small programs with large dependencies. Note the time to build the entire compiler and standard library is not extraordinary for a large program. It's more like, a small program adding its first few dependencies will find itself pulling in a lot of the standard library to compile, and then will level off in its compilation time.
To illustrate why this may be the case, consider the Crystal feature allowing redefining parts of classes, including ones in the standard library. This is both very useful, and if you think about how it affects features like incremental compilation, immensely complicating.
Here's some practical crystal programs.
This Postgres wire protocol driver is comparable to libpq in performance, and supports a lot of features in the protocol, too: https://github.com/will/crystal-pg/
The Crunchy Bridge CLI: https://github.com/CrunchyData/bridge-cli
Due to it's infancy the packages are sparse, so what some people do is a hybrid approach, where they write their thing in Ruby/Rails and kick out the slower parts to Crystal. This kinda gives the best of both worlds. Crystal (last I checked) had slow compile times, so gives you the dev velocity and package availability of ruby, plus the speed of a compile language when you need it. The compile times on Crystal stay low because you're only writing a small parts/microservices of your application in Crystal.
What's the story on Crystal/Ruby interop these days? I work on a Rails app that does document automation, and I could definitely find some specific < 1000 LOC segments that would benefit hugely from being 1:1 rewritten into Crystal and integrated with the rest of the app.
Http micro service, IPC, or FFI.
There were some attempts to do inline crystal, like what Mojo does in Python, but I don't know if any of them became stable long term solutions.
There's probably a way to get native C ext speed, you can see an old attempt here:
https://www.akitaonrails.com/2016/07/06/trying-to-match-c-ba...
But at any rate, it'll be better than ruby.
- compiled so easy to deploy
- easy to write compared to Rust, when you don't care about being super reliable
- still keeps things typed and better than in Ruby
- lower memory usage than Ruby/Python (and usually an easy 10x jump in performance)
I'm relying on it a lot with simple lambda automation. If I wanted to write an efficient server, I'd probably use rust though.
I enjoy writing it but don’t think there’s any particular reason to try/learn it, unless you happen to also be a ruby dev who prefers compiled, strongly typed languages.
https://forge.rust-lang.org/infra/other-installation-methods...
Also, the MSVC compiler itself often produces much worse code than clang or gcc. I am regularly astonished by its stupidity.