jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
deavmi has quit [Ping timeout: 258 seconds]
deavmi has joined #crystal-lang
oddp has quit [Ping timeout: 258 seconds]
mjblack has quit [Ping timeout: 265 seconds]
mjblack has joined #crystal-lang
deavmi has quit [Ping timeout: 256 seconds]
deavmi has joined #crystal-lang
<FromGitter> <wyhaines> @didactic-drunk So, the nutshell version is that I have a server that will potentially have hundreds of concurrent socket connections coming into it, feeding a continuous stream of data into the server. What I want to do is to have a pool of fibers that will service the incoming data, since the vast majority of that data handling will itself be IO blocked -- database inserts or other IO activity will be the
<FromGitter> ... end result of most of that data. ⏎ ⏎ In my ideal world, my implementation will work great on single threaded Crystal, AND when the time comes, and I have dealt with the fiddly bits of thread safety, it will also work if I build it under multithreaded Crystal.
<FromGitter> <didactic-drunk> All my code is tested MT daily. It also works single threaded.
<FromGitter> <didactic-drunk> With IO heavy workloads.
<FromGitter> <wyhaines> I'm refactoring some of the network internals tonight and tomorrow. I'll pull your code in and see if I run into issues.
<FromGitter> <didactic-drunk> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ef806bcfa0c9221fc650361]
<FromGitter> <didactic-drunk> I'm using similar code for a non HTTP service with sqlite as the backend.
livcd has quit [Ping timeout: 265 seconds]
<FromGitter> <wyhaines> That's fairly similar to what I will be writing. I just finished some other debugging, so I am looking at it right now.
<postmodern> do you still have to install the crystal snap with --classic? appears that newer snaps are phasing out classic snaps and the /snap, ~/snap directories.
<postmodern> also having trouble removing it once installed as a --classic
<FromGitter> <wyhaines> @didactic-drunk Well, my reaction upon integrating `concurrent/channel` and testing? ⏎ ⏎ "Holy shit that ran fast!" ⏎ ⏎ I appreciate how easy it was to just drop that into the code in place of the single-fiber code, and it *dramatically* increased my throughput. [https://gitter.im/crystal-lang/crystal?at=5ef81bd5fa0c9221fc652a3b]
postmodern has quit [Quit: Leaving]
postmodern has joined #crystal-lang
<postmodern> nevermind, i re-installed snapd, removed ~/snap, re-installed crystal --class and now the permission issues are fixed.
<postmodern> what is the preferred way to send stop messages via Channels? I saw in the docs that Channel(Nil) or Channel(Type?) is considered a bad practice.
<FromGitter> <didactic-drunk> `channel.close` ?
sagax has quit [Ping timeout: 246 seconds]
<FromGitter> <didactic-drunk> @wyhaines Try with -Dpreview_mt and --release. Compare runtime. You may exceed the db speed.
deavmi has quit [Ping timeout: 256 seconds]
deavmi has joined #crystal-lang
<FromGitter> <didactic-drunk> @wyhaines Beware of `serial`. Once you call that you're processing in the current fiber. If there's nothing feeding the stream it will hang.
alexherbo2 has joined #crystal-lang
deavmi has quit [Ping timeout: 264 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 256 seconds]
<oprypin> postmodern: yes send whatever sentinel you want
deavmi has joined #crystal-lang
<oprypin> send send send send close can lose the messages if the other side has not received them
<oprypin> send send send send send(nil) is reliable
<oprypin> cc @didactic-drunk
Nekka has quit [Quit: zzz]
Nekka has joined #crystal-lang
alexherbo26 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo26 is now known as alexherbo2
sagax has joined #crystal-lang
<FromGitter> <bararchy> we really need a `--no-cache` option for build :)
alexherbo2 has quit [Read error: Connection reset by peer]
<FromGitter> <bararchy> Is there a way to see how many Fibers running at a given time?
alexherbo2 has joined #crystal-lang
<FromGitter> <Daniel-Worrall> `(ENV["CRYSTAL_WORKERS"]?.try &.to_i) || 4` ?
<FromGitter> <Daniel-Worrall> oh wait, no
<FromGitter> <Daniel-Worrall> that's not what you're asking
<FromGitter> <bararchy> yeha :)
<postmodern> oprypin, how do you do the type signature for `Type | literal-sentinel-only`?
oddp has joined #crystal-lang
<yxhuvud> if your sentinel is nil it would be Type | Nil. If your sentinel is something else the general answer would replace nil with the output of typeof(whatever you use as sentinel value)
deavmi has quit [Ping timeout: 246 seconds]
deavmi has joined #crystal-lang
<oprypin> postmodern, using Nil is totally fine. or `record Sentinel; x : Int32 | Sentinel = Sentinel.new`
<oprypin> `module Sentinel; extend self; end; x : Int32 | Sentinel = Sentinel` 🤔🤔🤔🤔🤔🤔🤔
alexherbo24 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo24 is now known as alexherbo2
<sorcus> Hi :-)
<sorcus> BigInt implemented only as a C binding?
deavmi has quit [Ping timeout: 256 seconds]
<oprypin> sorcus, yes
deavmi has joined #crystal-lang
<FromGitter> <lbarasti> Macro related: could someone explain why this prints "V []"? I was expecting "V [v]" ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ef887ba613d3b339412c451]
<oprypin> lbarasti, it's being expanded within the context of macro included, not within the destination. add slash https://play.crystal-lang.org/#/r/9c5k
<FromGitter> <lbarasti> uh, I see, but isn't it weird that it resolves `V` correctly
<oprypin> lbarasti, damn dude i dont know,, i have only guesses
<oprypin> so *actually* seems like what i said is wrong
<oprypin> so it gets expanded in the destination but if u dont add the slash, it's expanded immediately and theres no instance var yet
<FromGitter> <lbarasti> well, your solution takes me out of my misery, at least :D
<oprypin> but if u add the slash, it's executed in the context *of that method*
<FromGitter> <lbarasti> 🙏
<FromGitter> <j8r> I'm thinking back of the infamous case of enums, uppercase or camecalse :P?
<FromGitter> <j8r> strange I found that using the symbol shortband on a camelcased enum, like`HTTP::WebSocket::CloseCode::GoingAway` is `:going_away`
<oprypin> whats strange
<FromGitter> <j8r> I thought to be `:goingaway`, but it makes sense
<FromGitter> <j8r> to have the underscore
<FromGitter> <j8r> Now I will favor enum with upper case, more consistent with snake case
<FromGitter> <j8r> nvm `:GoingAway` is also valid O.o
<FromGitter> <j8r> I will use this then, I didn't know tha(
<sorcus> Where i can find examples for `asm` in Crystal?
<sorcus> :-D
<FromGitter> <asterite> @lbarasti instance var information is macros inside methods, never in top-level macros
<FromGitter> <didactic-drunk> @postmodern @oprypin #close is a reliable way to indicate no more messages. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ef8b146405be935cdc9ebe8]
<oprypin> no, try it
<FromGitter> <didactic-drunk> @oprypin https://carc.in/#/r/9c6j
<oprypin> i suppose you're right with this example. i'm a bit confused, i must have been thinking of some different scenario
<FromGitter> <didactic-drunk> Multiple senders? If one closes the remaining can't send.
<FromGitter> <wyhaines> I can't get it to not behave as expected, either. My version was similar.
<yxhuvud> I can see closing it from the receiver side would be troublesome though.
masterdonx2 has joined #crystal-lang
MasterdonX has quit [Ping timeout: 246 seconds]
DTZUZU_ is now known as DTZUZU
yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
yxhuvud has joined #crystal-lang
<sorcus> No one knows how to use an assembler in crystal?
<FromGitter> <naqvis> sorcus, is that a question or a comment to some message in this channel?
<sorcus> naqvis: a question.
<FromGitter> <naqvis> so if your question is how to write assembler code in crystal, then I will doubt it
<FromGitter> <naqvis> you can write that in C and then do the linkage in Crystal
<sorcus> naqvis: I'm interested in trying the assembler inserts in crystal.
postmodern has quit [Quit: Leaving]
<FromGitter> <naqvis> sounds like a plan. Its good you can proceed with PoC then go with RFC
<sorcus> naqvis: RFC for what? o_O
<FromGitter> <naqvis> if I understand your intention correctly, then I was suggesting that once you have PoC ready, you can raise an RFC to add assembler support in crystal
<FromGitter> <naqvis> https://github.com/crystal-lang/crystal/issues/8307 might be a good reference (though I doubt if it answers the questions which you are asking)
<sorcus> naqvis: https://github.com/RX14/crystal/blob/master/spec/compiler/codegen/asm_spec.cr#L6-L12 - i mean this code. I want try to use `asm()` function in Crystal, but there is not much info about this...
<FromGitter> <naqvis> sorry, got no clue on this. But my guess is, this functionality is there for `--emit asm`
<FromGitter> <naqvis> but I might be wrong
<sorcus> naqvis: i'm not sure, because https://play.crystal-lang.org/#/r/9c87 it works not only for `--emit asm`...
<sorcus> naqvis: And i apologize for my English. X-)
<FromGitter> <naqvis> 🌹 , sorry don't have knowledge of this `asm` keyword
<FromGitter> <naqvis> let's wait for someone else to jump in and provide some insights
rocx has joined #crystal-lang
Human_G33k has quit [Ping timeout: 260 seconds]
HumanG33k has joined #crystal-lang
Human_G33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 265 seconds]
HumanG33k has joined #crystal-lang
Human_G33k has quit [Read error: Connection reset by peer]
<raz> is there any way to get usable backtraced out of a --static build nowadays?
<raz> tried with libunwind and such, but the most i could achieve is random segfaults at compile time (and still no backtraces when it doesn't fault) :(
<FromGitter> <Blacksmoke16> did you build with `--debug`?
<raz> no, should i try?
<raz> --static --release --link-flags "-static -lunwind"
<raz> that's what i got
<FromGitter> <Blacksmoke16> probably worth a shot
<FromGitter> <j8r> https://github.com/crystal-lang/crystal/pull/9238 did not fix this issue raz? Too bad :(
<raz> oh, i'm still on .34!
<raz> looks like i should make the jump
ua has quit [Ping timeout: 265 seconds]
ua has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 256 seconds]
<FromGitter> <ImAHopelessDev_gitlab> i'll join you
<raz> well, i'll defer it to a bit later. gotta nag didactic drunk to update zstd shard :p
<raz> seems like i can get my docker image small enough even without static (got it at around 35M now)
<raz> would be cool if static is fixed in .35 anyway. that removes so much headache from deployment
<FromGitter> <Blacksmoke16> Once it's static, throw it in a scratch image?
<raz> yup. saves you from having to get all the right libs in all the right versions on that image, too
<FromGitter> <didactic-drunk> @raz What doesn't work on 35.1? The specs pass and th write interface was rolled back.
<raz> didactic-drunk: shards says `crystal (0.29.0-dev)` required by `zstd 1.1.0`
<raz> i think it's because the new shards now takes the crystal version from shard.yml seriously (but haven't taken a closer look yet)
<raz> my guess would be the -dev suffix makes it unhappy
Human_G33k has joined #crystal-lang
<FromGitter> <didactic-drunk> Try now.
<raz> Installing zstd (1.1.1)
<raz> \o/
HumanG33k has quit [Ping timeout: 246 seconds]
<raz> now that's what i call customer service
* raz tries a build
<raz> works, yay
<raz> didactic-drunk: it seems something broke in sodium tho hmm
<raz> `Sodium::Digest::Blake2b.new.update("foo".to_slice).hexfinal`
<raz> Error: undefined method 'hexfinal' for Sodium::Digest::Blake2b
<raz> neither hexfinal, hexdigest nor final.hexstring works in my build for some reason
<FromGitter> <watzon> @bararchy there may be a way that doesn't require copying the `#initialize` function line for line, but this works https://carc.in/#/r/9c9h
<FromGitter> <dscottboggs_gitlab> if I were working on a project that had methods called that I might feel compelled to rename them like `#hex_final`..
<FromGitter> <dscottboggs_gitlab> Does Crystal have small-string optimization?
<oprypin> dscottboggs_gitlab, no
<oprypin> but hey there's a pretty good any-string optimization that it doesnt go through two pointers
<oprypin> in memory it's [length,bytesize,char,char,char,char,char] rather than [length,bytesize,pointer]
<FromGitter> <dscottboggs_gitlab> oh cool
<FromGitter> <dscottboggs_gitlab> I'm surprised but I did not think of that, that's a really cool way to handle that
deavmi has quit [Ping timeout: 265 seconds]
<FromGitter> <didactic-drunk> @raz New sodium release.
<raz> ha! right after i switched out my blake for ol'sha256 :D
<raz> gonna switch back tomorrow and will let ya know if it still bugs (gonna call it a night for now, but fwiw/fyi, all my other sodium stuff looks fine - was only blake that had a problem here)
<FromGitter> <didactic-drunk> @dscottboggs_gitlab `hexfinal` is an optimization of `hexdigest` which came from ruby. Me thinks maybe I should have left it as `hexdigest` for compatibility and let the programmer fix their code if it's called twice.
<FromGitter> <didactic-drunk> `hexfinal` is missing because I expected #9292 to be in 0.35.1.
<DeBot> https://github.com/crystal-lang/crystal/pull/9292 (Add faster Digest#hexfinal, Digest#hexfinal(dst))
<raz> yea nah, as long as it works i think the rename is fine
<FromGitter> <dscottboggs_gitlab> I see
<raz> best to stay 1:1 with stdlib digest, anything else just causes confusion
<raz> (i think stdlib marked hexdigest as deprecated, at least i got some warnings to that tune)
<FromGitter> <didactic-drunk> That was my PR.
<FromGitter> <didactic-drunk> I wanted #9292 and the other digest work to go together. It didn't work out that way.
<DeBot> https://github.com/crystal-lang/crystal/pull/9292 (Add faster Digest#hexfinal, Digest#hexfinal(dst))
<FromGitter> <didactic-drunk> Sodium was the testing ground for the 2 crystal PR's. Eventually I moved `hexfinal` to crystal after months of use. Sodium + the 2 PR's were meant to work together and partial backward compatible methods are available in sodium. They were all meant to work together, but upgraded in any order (upgrade sodium, or crystal or both). Not merging 9292 threw that off a bit.