<FromGitter>
<Blacksmoke16> havent used em too much
<FromGitter>
<mwlang> I'm not easily impressed, but I have to say after reading the guide on concurrency that this is the most intuitive way I have ever seen currency implemented in a language.
<FromGitter>
<Blacksmoke16> 💯
<FromGitter>
<mwlang> and yet another whole class of Ruby idioms I need to drop like a hot potato to do it the Crystal way.
<FromGitter>
<mwlang> one question: The guide states, "A Crystal program executes in a single operating system thread" Does this mean a crystal program won't take advantage of all CPU cores available on a computer? (same as Ruby)
<FromGitter>
<Blacksmoke16> crystal doesnt have MT yet
<FromGitter>
<Blacksmoke16> its single threaded
<FromGitter>
<mwlang> ok, so same thing with Ruby processes.
<FromGitter>
<mwlang> Proxy design pattern, I believe.
<FromGitter>
<Blacksmoke16> sec
<FromGitter>
<mwlang> a lot of indicators, like simple moving averages (SMA) or RSI have a lookback window (X number of candles) in their formulas, so a simple class like this can keep exactly the number of data points I want on the array at all times without explicitly managing in the SMA or RSI class.
<FromGitter>
<mwlang> btw, I didn't realize Crystal could reopen classes like Ruby can -- simply hadn't gotten that far, yet! Great example showing that.
<FromGitter>
<Blacksmoke16> can also include a `forward_missing_to @array` so that a method you dont define on `self` would attempt to use array
<FromGitter>
<Blacksmoke16> i.e. basic can use all array methods on it now
<FromGitter>
<mwlang> main diff is that it I almost always want to start counting at right-most (newest) values on the array
<FromGitter>
<Blacksmoke16> and they'll be forwarded to `@array`
<FromGitter>
<mwlang> so [-1] and [0] would be right-most element
<FromGitter>
<mwlang> [-2] and [1] would be next to last.
<FromGitter>
<Blacksmoke16> fair enough
<FromGitter>
<Blacksmoke16> sorry, another thing you could set the type of `max_size` to `UInt32`, then would get a compile error if you tried to use a negative value, vs a runtime error
<FromGitter>
<mwlang> that's why there's also a "safe_slice" in the beginning of populating the array, there's not enough elements to fill, say 10 values, so it's not just sum and divide by 10. we'll take mean from 2 elements until it reaches it's cap at 10 (or whatever it is we're doing with X number of elements where I need always X elements...the first element serves to fill up the void.
<FromGitter>
<Blacksmoke16> Not what I was expecting
<FromGitter>
<mwlang> I got slightly different results.
<FromGitter>
<mwlang> 1) 000661 for Array, 0.000420 for Deque
<FromGitter>
<mwlang> just using plain Benchmark.measure
<FromGitter>
<mwlang> you flipped the report names and the classes you invoked!
<FromGitter>
<Blacksmoke16> Lol
<FromGitter>
<Blacksmoke16> That would do it
<FromGitter>
<Blacksmoke16> Good call :p
<FromGitter>
<Blacksmoke16> Well there you go, the deque one is 9x faster in this test at least
<FromGitter>
<mwlang> I'm sold. going with Deque
<FromGitter>
<mwlang> premature optimization, but who cares! This is pure gold.
<FromGitter>
<mwlang> three days into Crystal and I'm already near enough to replace a giant mess of processes for collecting ticker, order books, and trade data from binance.
<FromGitter>
<mwlang> every trick in the book to boost Ruby was played from threading, to using Rake to fork multiple processes to pushing to Redis and later processing to DBMS with yet more processes, dockerizing the whole thing into microservices and so on.
<FromGitter>
<mwlang> one simple cyrstal script and we have enough performance to do it all.
<FromGitter>
<Blacksmoke16> Indeed
<FromGitter>
<Blacksmoke16> Maybe rerun that benchmark to simulate something you'd be doing
<FromGitter>
<Blacksmoke16> Like smaller size, less iterations etc
<FromGitter>
<mwlang> oh, I definitely will.
<FromGitter>
<mwlang> but the Deque class meets the exact needs I'm using it for.
<FromGitter>
<mwlang> constantly pushing data onto one end and shifting it off the other end.
<FromGitter>
<mwlang> tailor made, if you ask me.
laaron- has quit [Remote host closed the connection]
laaron has joined #crystal-lang
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter>
<Blacksmoke16> I guess so :)
alexherbo29 has quit [Ping timeout: 245 seconds]
laaron has quit [Remote host closed the connection]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
<jokke>
hey
<jokke>
afair crystal already kinda caches compile results somewhere to speed up subsequent compilations. Where is this cache located?
<FromGitter>
<Val> @jokke: See `CRYSTAL_CACHE_DIR` environment variable, default is `$HOME/.crystal` as far as I know
<jokke>
ah nice thanks
<FromGitter>
<Val> `man crystal`
ashirase has quit [Ping timeout: 244 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
DTZUZO has quit [Ping timeout: 255 seconds]
ashirase has joined #crystal-lang
RyanMcCoskrie has joined #crystal-lang
<FromGitter>
<mavu> Morning, I want to automatically include/read version information when the project is compiled.
<FromGitter>
<mavu> does anyone have a quick link or hint for some inspiration of how to do that? (i.e. steal code) :P
<FromGitter>
<mavu> for example, read the debian changelog file and extract the topmost entry, or start a command and capture its output at compile time
RyanMcCoskrie has quit [Remote host closed the connection]
dom96 has quit [Ping timeout: 255 seconds]
dom96 has joined #crystal-lang
<FromGitter>
<bew> You can do that from macros, using simple shell commands, or if you need to do more, use the `run` macro method
<FromGitter>
<r00ster91> you need to put 3 ` at the end too
<FromGitter>
<mavu> thanks, reading is a skill I still need to master :)
<FromGitter>
<gdotdesign> @mavu I managed to clear the cache with `rm -rf ~/.cache/crystal` (Ubuntu)
<FromGitter>
<gdotdesign> > for example, read the debian changelog file and extract the topmost entry, or start a command and capture its output at compile time? ⏎ ⏎ You can execute commands in a macro, in Mint it reads the version from the yaml file: https://github.com/mint-lang/mint/blob/master/src/commands/version.cr#L10
<jokke>
can i create a named pipe/fifo with crystal?
<jokke>
i need to pass a file descriptor to a c lib but don't want to write the data to a file
DTZUZO has joined #crystal-lang
<FromGitter>
<bew> jokke: there is `LibC.mkfifo`, but no wrapper
<mps>
j8r: speaking aobut crystal apk, I had to disable one 'spec' check, 'it "detects stack overflow on the main stack" do' in spec/std/kernel_spec.cr
<mps>
what do you think, is it safe or it needs fix in crystal
<mps>
also, straight-shoota what do you think about it
<jokke>
yup found it!
<jokke>
thanks bew
<FromGitter>
<mwlang> great write up on crystal performance with insight relative to same issues in Ruby. This was a great way for me to start to unlearn a few Ruby hacks garnered over the years for various micro-optimizations: https://github.com/konung/fast-crystal
<FromGitter>
<mwlang> comparing Go, Ruby, JS, Python and Crystal. That doesn't seem right to me given what I've seen already in, oh, four days now.
<FromGitter>
<kinxer> I hope they compiled with `--release`. :P But it could be because Crystal isn't multithreaded yet.
<FromGitter>
<straight-shoota> mps, yes it's totally fine to ignore this spec
<z64>
you could check; the techempower configs are in a repo somewhere. IIRC they might already be doing something like `SO_REUSEPORT` with multiple processes to compensate that mt hasn't landed yet
<FromGitter>
<straight-shoota> This is already tracked in #7482
<FromGitter>
<mwlang> I checked. They're compiling with nodebug and release flags.
<FromGitter>
<ArtLinkov> Hi all, ⏎ I'm looking for a library that can parse a PNG file and returns an object that includes all the params and extension (i.e png.timestamp >> date+time_
<FromGitter>
<shreeve> keys of SOCKETS variable are (HTTP::WebSocket | String)...
<FromGitter>
<Blacksmoke16> got a playground link?
<FromGitter>
<asterite> You can do `SOCKETS.keys.select(String).sort` if you are on 0.28.0
<FromGitter>
<Blacksmoke16> neat
<FromGitter>
<shreeve> I'm selecting just the stings out from the keys and then trying to sort, but getting an error that it cannot sort websockets (but the array will only have strings, so it should be ok)
<FromGitter>
<shreeve> Aw! Great... trying now!
<FromGitter>
<shreeve> beautiful! I *am* on 0.28.0, so that worked great!
<FromGitter>
<shreeve> Thanks @asterite!
<FromGitter>
<asterite> The "problem" with the original code is that the compiler can't figure out that only things of type `String` remain in the array (the `is_a?`thing only works for local variables)
<FromGitter>
<asterite> glad to help :-)
<FromGitter>
<Blacksmoke16> *interesting*
<FromGitter>
<shreeve> That worked perfectly... :-)
<FromGitter>
<shreeve> the sort (first line) works great with 0.28.0 (clean!), the second line still has the "problem", since I can't tell the compiler that the only SOCKETS[connid] values will actually be HTTP::WebSocket objects... any way for me to say, "it's ok... I'm only passing values that are websockets?"
<FromGitter>
<Blacksmoke16> would a `.as(HTTP::WebSocket)` solve that?
<FromGitter>
<shreeve> where would I add that @Blacksmoke16 ?
<FromGitter>
<Blacksmoke16> @mwlang Remembered you can prob squeeze another 1x perf out of your boundArray by doing like `@array = Deque(T).new @max_size`
<FromGitter>
<Blacksmoke16> could also do the same for your array, prob make that a bit faster as well
<FromGitter>
<mwlang> I gotta learn how to do markdown in gitter :-/
<FromGitter>
<mwlang> That made the array implementation slightly slower.
<FromGitter>
<Blacksmoke16> really?
<FromGitter>
<Blacksmoke16> welp
<FromGitter>
<mwlang> but doesn't matter. I'm going with Deque in the implementation.
<FromGitter>
<mwlang> I'm going to focus for a while on building using revelations from those fast-crystal idioms I shared earlier.
<FromGitter>
<Blacksmoke16> sounds like a plan
<FromGitter>
<mwlang> can circle back and optimize where performance dictates.
laaron- has joined #crystal-lang
laaron has quit [Ping timeout: 256 seconds]
olbat has quit [Max SendQ exceeded]
<FromGitter>
<jaydorsey> @mwlang what was the time diff between crystal & ruby for what your’e working on?
laaron- has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter>
<mwlang> huge. Let me run the benchmark again now that I know a little more what I'm doing.
<FromGitter>
<mwlang> I'll be back in a few minutes and get this measured and posted.
<FromGitter>
<bew> "a few minutes later.." *just kiddin'*
<FromGitter>
<jaydorsey> Lol
<FromGitter>
<bohtho> Never to be seen again. The old bait and switch. Leaving us all paralyzed like deer in headlights. He could be an agent from Nim 🤪😄
<FromGitter>
<mwlang> Haha.
<FromGitter>
<mwlang> Ruby script still running. I had been improving the Crystal code and optimizing since originally writing it.
<FromGitter>
<mwlang> then I needed to adjust Ruby code to match logically.
<FromGitter>
<mwlang> The code computes Bollinger bands for 450,000 data points.