ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.2 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
rcvalle has quit []
rohitpaulk has joined #crystal-lang
krystal has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
<krystal> Question about dealing with union types that contain Nil. For example Http::Request.query. If no query parameters are set this is Nil . You can't write code like if (context.request.query && context.request.query.SomeStringFunction) . You can do if q = context.request.query and then another if statement. What is the canonical Crystal way to handle things like this?
<FromGitter> <ezrast> @krystal Either what you said, or `context.request.query.try &.some_string_function`
<krystal> Thanks I didn't notice try before. It's not referenced anywhere in the main docs. May be nice to put it on the Union types page or Nil page maybe?
<krystal> nevermind it's in the same section i got the other solution from :)
krystal has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
davic has quit [Quit: ZNC - http://znc.in]
davic has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
<FromGitter> <girng> https://stackoverflow.com/a/29885992/7873241 Is this answer an accurate description of how heap memory works within a Crystal app? I know it says nodejs, but I was testing my tcp server on crystal, and then in a nodejs one. And in fact, they do the same thing. They "Plateau" to a certain amount of memory, but don't go down. But it doesn't mean it's a memory leak, it just means the OS then has to determine when it
<FromGitter> ... wants that memory back. Under extreme stress, etc. If I got that right, I think? :)
<FromGitter> <girng> When he says "heap manager", is he referring to a garbage collector?
ua has quit [Quit: Leaving]
ua has joined #crystal-lang
qard has joined #crystal-lang
Guest3612 is now known as baweaver
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
qard has quit [Quit: qard]
<FromGitter> <Grabli66> Hi! How to close all forked processes?
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
DTZUZO has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 248 seconds]
Nik736 has joined #crystal-lang
rohitpaulk has joined #crystal-lang
Nik736 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <yorci> hey all, Crypto::Bcrypt::Password is terribly slow, any improvements plan ?
<FromGitter> <sdogruyol> there's an issue about it
<FromGitter> <sdogruyol> but it shouldn't be terribly slow?
<FromGitter> <sdogruyol> actually it should be OK after we merged this
<FromGitter> <yorci> i get 1400~ ms for only hash string for comparing with cost 10
<FromGitter> <sdogruyol> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b07cdabc5750d377c0fd534]
<FromGitter> <sdogruyol> `bcrypt 13.19 ( 75.81ms) (± 3.22%) 5613 B/op fastest`
<FromGitter> <yorci> 😟
<FromGitter> <sdogruyol> are you on a really low-end box?
<FromGitter> <yorci> actually nope, im testing on my development machine with ryzen 1700 and linux mint as OS
<FromGitter> <sdogruyol> that's interesting then
<FromGitter> <sdogruyol> can you compile and run the snippet that I shared?
<FromGitter> <sdogruyol> `crystal build --release bcrypt.cr && ./bcrypt`
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 252 seconds]
Raimondii is now known as Raimondi
<FromGitter> <yorci> ohh sorry, with --release option the result is very affected
<FromGitter> <yorci> `bcrypt 15.92 ( 62.82ms) (± 2.23%) fastest`
<FromGitter> <yorci> and in my application its reduced to 140~ ms
<FromGitter> <yorci> thank you Serdar
<FromGitter> <sdogruyol> you're welcome @yorci
<FromGitter> <sdogruyol> --release does a lot of optimizations, there can be major runtime performance difference
<FromGitter> <yorci> yep its impressive 👍 😄
<FromGitter> <Grabli66> How to get total running fiber count ?
<FromGitter> <sdogruyol> hmm..that's an interesting question. Never tried that
<FromGitter> <Grabli66> :)
<FromGitter> <Grabli66> May be i created millions of them. I want to know :)
<FromGitter> <sdogruyol> this was quick, there you @Grabli66
<FromGitter> <sdogruyol> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b07d668361a950a66141396]
Nik736 has joined #crystal-lang
Nik736 has quit [Client Quit]
Nik736 has joined #crystal-lang
<FromGitter> <Grabli66> It always returns 0. https://play.crystal-lang.org/#/r/4529
<FromGitter> <straight-shoota> stack_pool is a pool of unused fiber stacks
<FromGitter> <straight-shoota> if a fiber is finished, it's stack memory is made available in the stack_pool for the next fiber to use
dragonkh has quit [Quit: Textual IRC Client: www.textualapp.com]
<FromGitter> <straight-shoota> active fibers are accessible as a linked list from `Fiber.@@first_fiber`
Guest38236 is now known as RX14
<FromGitter> <straight-shoota> you can traversed this list to get the number of fibers: https://play.crystal-lang.org/#/r/452f
RX14 has quit [Quit: Fuck this shit, I'm out!]
RX14 has joined #crystal-lang
<FromGitter> <Grabli66> You dont count a first fiber. And why 13? :)
<FromGitter> <Grabli66> Main fiber + 10 spawned = 11
<RX14> we have fibers spawned in the stdlib
<RX14> one for the libgc event loop
<RX14> one of the signal handler I think
<RX14> actually there's one for clearing up stacks too
<RX14> so i thought there was 3 in the stdlib
<FromGitter> <Grabli66> Great thanks.
<RX14> yep
<RX14> i count 3 spawned in the stdlib
<FromGitter> <pynixwang> what plan for multicore ?
<FromGitter> <Grabli66> Parallelism? :)
<FromGitter> <pynixwang> yes
<FromGitter> <Grabli66> No. It was question for RX14. :)
<FromGitter> <Grabli66> I think he sees this question ten thousand times a day.
<FromGitter> <pynixwang> aha
Raimondii has joined #crystal-lang
<FromGitter> <straight-shoota> @Grabli66 first fiber is main. If you count it or not depends on the semantics
thews has quit [Excess Flood]
thews has joined #crystal-lang
thews has joined #crystal-lang
thews has quit [Changing host]
Raimondi has quit [Ping timeout: 264 seconds]
Raimondii is now known as Raimondi
<crystal-gh> [crystal] petoem closed pull request #5306: Prevent Time::Span overflow (master...fix-time_span) https://git.io/vFDMX
rohitpaulk has quit [Ping timeout: 245 seconds]
rohitpaulk has joined #crystal-lang
<hmans> Is there even a plan (in terms of planning, not intention) for a new release?
shalmezad has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
duane has joined #crystal-lang
<FromGitter> <sdogruyol> Yes @hmans
<FromGitter> <sdogruyol> We are preparing for a new release
<hmans> sdogruyol \o/
<hmans> Enjoy Balkan Ruby
<FromGitter> <sdogruyol> Thank you, are you there?
<hmans> I'm afraid not
<hmans> It's good to see that there's a lot of chatter about Crystal going on.
<hmans> Wasn't there also going to be a new Q&A on Reddit?
<FromGitter> <sdogruyol> we're also planning the next Q&A
<FromGitter> <Grabli66> Soon?
return0e has quit [Remote host closed the connection]
rohitpaulk has quit [Ping timeout: 240 seconds]
return0e has joined #crystal-lang
return0e has quit [Read error: No route to host]
Nik736 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
return0e has joined #crystal-lang
DTZUZO has joined #crystal-lang
That_Guy_Anon has joined #crystal-lang
wontruefree has joined #crystal-lang
dragonkh has joined #crystal-lang
wontruefree has quit [Client Quit]
wontruefree has joined #crystal-lang
<dragonkh> hi - in Ruby if I do 198.chr I get \xC6 - how do I do this in Crystal - I get this character: 'Æ'
<FromGitter> <bew> What happens in ruby if you print \xC6 ?
<dragonkh> I get a question mark symbol
<dragonkh> ah it's ok now
<dragonkh> the problem has gone away lol !
<dragonkh> ah I see I made a mistake earlier - ok great thanks - it's all good :)
<RX14> the socket library is a shitshow
<RX14> i'll have to rework all that before I get winsock working
<RX14> good excuse to anyway
<FromGitter> <bew> In what ways? I have things to say on the UNIXSocket side (and I already said them actually)
<RX14> well, first of all we shouldn't have both client and server sockets inherit from Socket
<RX14> yeah they're both FDs but theyr'e really different in use
<RX14> and then you've got a lot of inheritance mess
<FromGitter> <bew> Right, also it's not typesafe, 'cuz you can call receive on a server and it doesn't make any sense
<RX14> yeah
<RX14> for some of the insanity
<FromGitter> <bew> The same goes for stream/dgram/others sockets, they must be used differently based on their socket type (I have no idea how to make that cleanly though)
<RX14> we should provide a `Crystal::System::Socket` with all the BSD socket primitives
<RX14> then wrappers for {UDP,TCP}{Server,Client}
<RX14> oh
<RX14> and UNIX?
<RX14> but UNIX sockets can be any proto right
<RX14> so unix sockets should just be UDP or TCP server/clients?
<RX14> and just deal with the bad naming
<RX14> we could call it StreamServer.{tcp,unix}
<RX14> but that would be hard to discover in the docs
<RX14> because people aren't used to thinking stream/datagram instead of tcp/udp
<FromGitter> <Grabli66> Maybe don't do this? Everything is working now. And it's need a lot of time to rework, i think :)
<RX14> no
<RX14> why would we release 1.0 with a known-substandard interface
<FromGitter> <Grabli66> Great. I just tested your will. 😄
<RX14> guess it's time to stop procrastinating writing the 0.25.0 changelog
<FromGitter> <Grabli66> It's time to write some code
<FromGitter> <bew> RX14 do you have some control on the google group?
<RX14> no
<RX14> yes
<RX14> thanks for reminding me to bring it up
<FromGitter> <bew> Who has control?
<RX14> dunno
<FromGitter> <bew> I signaled them to google at least
<RX14> i'm thinking of just using zmq for parallel.cr
<RX14> it's fast, can be integrated into the event loop and provides good IPC
<FromGitter> <bew> iirc our zmq wrapper doesn't handle signal or sth like that, but maybe not needed for this
<RX14> last I heard the zmq wrapper wasn't even evted
<RX14> evented*
<RX14> nope
<RX14> the zmq lib needs to be scrapped, it's terrible
<FromGitter> <bew> scrapped?
Nik736 has joined #crystal-lang
Nik736 has quit [Client Quit]
Nik736 has joined #crystal-lang
<FromGitter> <bew> RX14 why zmq for simple IPC, pipes not enough?
snsei has joined #crystal-lang
<RX14> hmm
<RX14> i'm not certain of the best way to do this to be honest
<RX14> the thing is locking on the FDs
<RX14> we want atomic sends and recieves
<RX14> so you'd need locking on the pipe
<RX14> which means the locks would have to be in shm
<RX14> and then somehow you'd have to integrate the locks into the event loop? eugh
<FromGitter> <bew> didn't thought about that
That_Guy_Anon has quit [Remote host closed the connection]
<FromGitter> <girng> Nice! So I'm doing some testing with my socket.cr and server.cr. I bought a new KVM VPS, and their cpu specs are here (https://i.gyazo.com/8795db56419e8434eda7c26ab1a5092f.png). I am not sure how much is actually given through a "Virtual Core". But I changed my `socket.cr` to send a message to the server every 6 seconds. I loaded up 8,000 connections (https://i.imgur.com/kpl3zOX.png).
<FromGitter> <bew> I'm not sure it's what you want, it seems you can't send data with eventfd
<RX14> i know
<FromGitter> <bew> ah you want to use that in addition to pipe?
<RX14> yeah you'd have to
<RX14> actually
<RX14> maybe not
<RX14> (lol)
<RX14> might be able to do it entirely with shm and atomics
<RX14> each process would have a shm pool which was mapped into every other process
<RX14> (assuming that can be done, which is shard)
<RX14> the PChan is allocated in that shm pool
<RX14> senders serialize their objects to shm
<RX14> then attempt to spinlock on ...
<RX14> no this wouldn't work
<RX14> you essentially need a readers lock and a writers lock and a pipe
<RX14> and the reader and writers locks need to be put into the evnt loop
<RX14> the pipe can be replaced with shm
<RX14> but the locks needs to be evented
<RX14> nope, the locks AND the pipe need to be evented?
faustinoaq has joined #crystal-lang
<RX14> nope we need eventfd and pipe
<RX14> this is actually a hard problem
<RX14> you could probably replace the pipe with shm if readers tried to acquire the write lock as well?
<RX14> and thats all only for unbuffered pipes
<RX14> buffered pipes are a whole new can of worms lol
<RX14> i think i need to work this design out on paper
shalmezad has quit [Quit: Leaving]
<FromGitter> <bew> I like the idea of using shm to pass the data! but this can work only in one direction, right? so you'd need 2 for bidirectional communication
That_Guy_Anon has joined #crystal-lang
faustinoaq has quit [Ping timeout: 248 seconds]
<RX14> well yeah
<RX14> channels only work in one direction
<RX14> and how often do you find that a problem
<FromGitter> <bew> hm yeah not a problem actually, if you want bidirectional you make 2 channel..
<FromGitter> <bew> RX14 do you think macros are slow?
<RX14> i know they're slow
<RX14> lol
<FromGitter> <bew> hmm yes obviously :P I'm thinking about extracting the literal expansion out of the compiler, and using macros in the stdlib for that, I need to bench that see if it's horrible or not
<FromGitter> <bew> would be nice to be able to put annotations on macros :P
<FromGitter> <bew> like `@[LiteralExpander(ArrayLiteral, when: (node.of && node.size == 0))]` on top of my macro for that
<RX14> what are you trying to do?
<FromGitter> <bew> move this file out of the compiler, to the stdlib https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/semantic/literal_expander.cr
<FromGitter> <bew> "try" at least
<RX14> whyy
<FromGitter> <bew> yeah maybe not that good of an idea.. I was thinking about making the compiler more stdlib agnostic, so that you can build your own library for the same language, that could work differently, different classes (and maybe only structs), can disallow some literal by raising on their expansion, ....
<RX14> yeha that'd be cool
<RX14> but
<RX14> thats not the place to start
<FromGitter> <bew> it's just an idea I got a few days ago, wanted to try it out
duane has quit [Ping timeout: 248 seconds]
<FromGitter> <bew> for fun: https://gist.github.com/bew/9296a477ca60eb979af7d27dda1fb4d0 the actual expansion feels more readable than in the compiler (but it comes with the overhead of macros)
krystal has joined #crystal-lang
<FromGitter> <manveru> is there some way to make errors like `in server.cr:188: instance variable '@last_value' of Boxes::Box(NamedTuple(display: String, headers: String, rows: Array(Array(String)))) must be NamedTuple(display: String, headers: String, rows: Array(Array(String))), not NamedTuple(display: String, headers: Array(String), rows: Array(Array(String)))` display more like ⏎ ⏎ ```code paste, see link```
<FromGitter> <manveru> so it's easier to see the issue?
<Yxhuvud> well, if you know the type of a likely error (or a likely too broad error) you can make an error overload that fits the error and raise during ompile time with the error you want
<FromGitter> <manveru> i meant more... language wide
<FromGitter> <manveru> i know the better way is to make a type alias, but i sometimes encounter such errors that run a few lines and i have to put in a text editor to decipher
wontruefree has quit [Quit: bye]
<Yxhuvud> well, sometimes it is quite conventient to type method arguments or return values to fence in the issues
wontruefree has joined #crystal-lang
<FromGitter> <bew> that's an idea @manveru but I'd do: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b0880b8361a950a6616d4b4]
Nik736 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <bew> I think `must be` and `not` hard hard to see with your version
<FromGitter> <manveru> that looks better, yeah
<FromGitter> <bew> maybe that could be done when one of the type is long (more than X chars)
<FromGitter> <manveru> i'm just using elm and crystal and it's quite a big gap in error reporting friendliness :)
<FromGitter> <bew> I don't know elm
wontruefree has quit [Client Quit]
<FromGitter> <manveru> http://elm-lang.org/blog/compilers-as-assistants has a good introduction about the error reporting
<FromGitter> <bew> indeed it's quite different
krystal has quit [Quit: Page closed]
<FromGitter> <bew> I think you can open an issue about that, see how it goes ;)
sz0 has joined #crystal-lang
snsei has quit []
wontruefree has joined #crystal-lang
RX14 is now known as Loki_Laufeysdott
Loki_Laufeysdott is now known as RX14
snsei has joined #crystal-lang
wontruefree has quit [Client Quit]
That_Guy_Anon has quit [Quit: Leaving]
wontruefree has joined #crystal-lang
notdaniel has joined #crystal-lang
wontruefree has quit [Quit: bye]
<FromGitter> <manveru> given `@boxes : Array(Boxes::Text | Boxes::Images | Boxes::Table | Boxes::Iframe)`, is there a way to make a macro that creates that union for all subclasses of `Boxes::Box` instead?
<FromGitter> <manveru> i'm not sure how i'd create a new `Crystal::Macros::Union` instance
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
notdaniel has quit [Ping timeout: 252 seconds]
<FromGitter> <bew> Just `Type1 | Type2`
<FromGitter> <bew> You can also make an `Array(Box) `
<FromGitter> <manveru> my problem is that `Box` is actually a `Box(T)`, so `Array(Box)` won't compile
<FromGitter> <manveru> so, i know i can write them all by hand, but i was wondering if this is something possible with macros :)
notdaniel has joined #crystal-lang
<FromGitter> <manveru> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b0897e4b6eece791db35b87]
<FromGitter> <manveru> that seems to work
<FromGitter> <manveru> but then i get this error
<FromGitter> <manveru> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b08989716f6496124df996c]
<FromGitter> <manveru> oh well, it was worth a try, but seems like this is some kind of compiler bug because that's clearly a subset, so it should be fine?
go|dfish has quit [Ping timeout: 268 seconds]
<FromGitter> <bew> How is that a compiler bug ?
<FromGitter> <bew> Ah
<FromGitter> <bew> No, `Array(X)` is different than `Array(X | Y)`, that's how things currently are
<RX14> and will always be
<FromGitter> <manveru> basically https://play.crystal-lang.org/#/r/4594
<FromGitter> <manveru> so i have to return all the different types in my array or it's not valid
faustinoaq has joined #crystal-lang
snsei has quit [Remote host closed the connection]
go|dfish has joined #crystal-lang
notdaniel has quit [Ping timeout: 245 seconds]
notdaniel has joined #crystal-lang