<FromGitter>
<girng> are namedtuples passed by value or reference?
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
That_Guy_Anon1 has joined #crystal-lang
That_Guy_Anon has quit [Ping timeout: 240 seconds]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter>
<bew> Value
<FromGitter>
<girng> awww crap....
Yxhuvud has joined #crystal-lang
<FromGitter>
<girng> i need to re-factor all my code then i think. cuz im creating named tuples for each game function and sending that to my .send method as a parameter. so it's basically copying all the data since it's passed by value
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<FromGitter>
<bew> hhm yes, but in your namedtuple you can have classes (e.g String, Hash, ...), and those will be passed by reference
<FromGitter>
<bew> I replied to you, but you can simply ask here you know
<FromGitter>
<faustinoaq> Hi crystal community, I have a question, I need to start my Undergraduate thesis, I have no idea what topic to choose, My career is "Ingeniería Informática" (something like Computer Science mixed with Soft Eng), My university is not the best, so I learned a lot of stuff on Internet by myself. On latest months I have made big collaborations to scry [Language Sarver Protocol for Crystal] and amber [Web
<FromGitter>
... Framework for Crystal], I think would be nice to do my thesis about crystal or some related project, WDYT?
<FromGitter>
<bew> @girng as you can see here https://play.crystal-lang.org/#/r/3uwu, your NamedTuple is 16 bytes, => 2 x 8 bytes (a pointer is 8 bytes), so it's very light, you shouldn't worry about it
<faustinoaq>
OvermindDL1, ^^ Maybe you can suggest me some topic :)
blackchalk has joined #crystal-lang
blackchalk has joined #crystal-lang
blackchalk has quit [Changing host]
<OvermindDL1>
What are you specializing in?
<faustinoaq>
I like programming languages and development tools
<OvermindDL1>
Hmmm, does Crystal have a good IDE yet? Perhaps write a plugin for IntelliJ or KDevelop as they are significantly more powerful than language-server based IDE's?
<faustinoaq>
I tried security and IoT but I think I haven't invested enough time on those fields
<FromGitter>
<girng> @bew thank you. yah but players send a lot of messages and overtime it might add up overtime, am a bit worried
<FromGitter>
<bew> naa, really it's nothing
<OvermindDL1>
Cool so you already have experience, you could easily make a high-end plugin then
<OvermindDL1>
The language server protocol is such garbage for static languages, dedicated plugins are so much more powerful. :-)
<OvermindDL1>
'though more work
<FromGitter>
<bew> why do you think that for static langs?
<faustinoaq>
Yeah, would be nice, but My professors said I must have a Justification for this and solve some kind of problem, I'm afraid they could say my work isn't useful because crystal is still in pre-alpha state
<FromGitter>
<bew> @girng if the namedtuple was huuge, maybe around 64-128 bytes, you can start finding an alternative, but not for 16 bytes!! You'll have plenty of other things to optimize before having to optimize this!
<faustinoaq>
OvermindDL1, WDYT about making a undergraduate thesis of this ^ framework?
<FromGitter>
<girng> @bew yeah understandable, but that 16 bytes gets duplicated each time the methodis ran... this will add up really quickly overtime for the length of the server :(
<FromGitter>
<girng> especially if players are sendnig/chatting a ton
<OvermindDL1>
A variety of reason including but not limited to slow callbacks, not handling multiple errors in source well, debugging is a joke, intellisense tends to be *way* slow, etc...
That_Guy_Anon2 has joined #crystal-lang
<OvermindDL1>
Now of course the language server protocol is great for getting a minimal viable thing out, but it is not complete by any stretch
<faustinoaq>
Or maybe I can do some kind of research comparing Crystal with other languages, WDYT?
<FromGitter>
<girng> @faustinoaq i thnk your crystal for windows is pretty cool in of itself
<OvermindDL1>
Like language servers are great for simple things like the vscode editor, but not really for plugins for full IDE's like KDevelop/IntelliJ/VStudio
<OvermindDL1>
faustinoaq: What kind of comparisons would you make?
<FromGitter>
<bew> @girng that's will most probably not be your bottleneck for performance... I suggest you develop your game server, make some performance tests, and if that's your slowest thing, then come back here and we'll discuss! but don't optimize things too early, that's useless
<faustinoaq>
OvermindDL1, Have you made some paper or research about computer science before?
<OvermindDL1>
Not much publically, I keep getting invited to speak at conferences but I don't have the money or time to go
<FromGitter>
<girng> @bew i think im not conveying my issue very well
That_Guy_Anon1 has quit [Ping timeout: 268 seconds]
<FromGitter>
<girng> im not worried about performance i know crystal is very fast. im saying, if the namedtuple gets copied.. tjhat means each time that method is run the namedtuple (not the data) gets copied. so.. that means the more times that method gets called, the higher the memory usage
<FromGitter>
<girng> which means fi the server has a bunch of players online 16*1, 2, 3, 4, 5, keeps going on and on and then the memory will be exhaustive in no time
<FromGitter>
<girng> there mut be a way to pass it by reference so no copying happens
<faustinoaq>
OvermindDL1, Oh, ok, my other issue about making and undergraduate thesis related to crystal can be the references, I think don't exist books or academic references to crystal yet :(
<OvermindDL1>
No books on crystal yet? Why don't you do that!
<faustinoaq>
^ These are my favorite papers in my Zotero library :)
<FromGitter>
<bew> @girng do you know how does the stack work and how it's used?
<faustinoaq>
OvermindDL1, Then, do you think a book would be a nice work for an undergraduate thesis in CS?
<FromGitter>
<girng> iuno how its used but i know the stack is faster than the heap and heap
<FromGitter>
<girng> heap is for storing large amounts of memory?
<OvermindDL1>
faustinoaq: Definitely, it focuses on lots of useful things like technical writing, learning the language in depth, communication, etc...
<FromGitter>
<bew> @girng very basically, the stack is where all your local variables are stored, and when the current function is finished, the space used for this function is "free"-ed, and will be reused for other things
<FromGitter>
<girng> so my `player1.send temp_data, "CHAT"` goes into the stack (the 16 bytes get copied, just the Namedtuple), then free'd?
<faustinoaq>
Oh, I just remember @sdogruyol is writing a book about crystal as well
<FromGitter>
<bew> @girng also, the stack has all the local vars of all the functions before you, so the stack will not grow that much, unless you have a recursive function that calls itself many time
<FromGitter>
<girng> @bew ohhh so that's why HASHES are so bad then.. because they are ALLOCATED on the heap! which doesn't get freed on the stack. it all makes sense now
<faustinoaq>
OvermindDL1, Maybe I can do a book in spanish then, WDYT? because English isn't my first language :(
<faustinoaq>
I can use English, but I'm not very proficient on it. I use google translate very often
<FromGitter>
<bew> @girng yes you can see it that way
<OvermindDL1>
Other languages are always useful, depends on how well it will sale, asking a publisher like manning or so is a good way to find out
<FromGitter>
<girng> @bew so if we replaced my code here https://play.crystal-lang.org/#/r/3uws to use a hash instead of a namedtuple, we'd have problems?
<FromGitter>
<bew> well, you'll have a huge overhead of allocating memory in the heap (small area each time), and put pressure on the GC to free that memory later
<FromGitter>
<girng> so technically, the values of temp_data are not copied but apssed by reference. but even if they were COPIED, it doesn't even matter becaue the stack will free them up eventually? butt hey are passed by reference because it is faster than a copy (crystal does this optimization internally)?
<FromGitter>
<bew> note: crystal doesn't do any optimization, llvm does (in release mode)
<FromGitter>
<bew> in the last link, it's still a namedtuple though
<FromGitter>
<bew> you know what, passing the namedtuple or passing each field of the namedtuple as argument to a function is exactly the same memory and performance-wise
<OvermindDL1>
Isn't there a way to inplace-allocate a limited-size hashmap in crystal?
<FromGitter>
<girng> the gc doesn't release memory to OS so when you say FREE, you don't rreally mean free do you? what is free mean in this sense?
<FromGitter>
<bew> free => can by reused by your program later
<FromGitter>
<girng> but it does grow larger n larger on the heap?
<FromGitter>
<girng> if using hash
<faustinoaq>
Maybe I can use his book as inspiration :)
<FromGitter>
<bew> @girng I don't understand your last question
<OvermindDL1>
faustinoaq: Heh, very likely yeah
<FromGitter>
<bew> @OvermindDL1 what do you mean by "inplace-allocate" ?
<OvermindDL1>
<language>-in-action is a very popular book name for a book on 'how to do real work'
<OvermindDL1>
bew: Like if a hashmap is in a class and you know it cannot have more than oh 4 elements in it, allocate all necessary memory 'with' the class then, or on the stack, or where-ever you wish
<OvermindDL1>
Pretty trivial in most machine code languages
<FromGitter>
<girng> if allocations a ton of hashes it doesn't get allocated on the stack, but the heap right? so you said the GC will most likely "FREE" that memory up. however, that memory could have risen to like 500MB usage before the GC kicks in. but even then, the memory doesn't get allocated to the OS. so, the GC will "free" up that memory for the crystal app to re-use, HOWEVER the app si still going to be at 500MB USAGE
<OvermindDL1>
Such as in an array, if you know not more than 4 or so elements then can just bulk allocate them all at once
<OvermindDL1>
An actual array*
<faustinoaq>
OvermindDL1, Nice! I will write something about this and discuss the idea with my professors, Thank you so much for your advices!
<OvermindDL1>
faustinoaq: And don't discount adding it to you resume, writing books is great for that
<OvermindDL1>
Don't expect to make money though to be honest, do it because you want to
duane has quit [Ping timeout: 264 seconds]
<FromGitter>
<bew> @OvermindDL1 I wish we could do that, but no, a class will always be allocated in the heap, and a struct in the stack, there's an issue opened about that (allocate what you want where you want) but it's stuck
<FromGitter>
<bew> for a simple array you can allocate a StaticArray of a specific size, which is basically a bunch of stack memory you can use
<FromGitter>
<bew> @girng I don't see where you want to go, but yes that's motly correct
blackchalk has joined #crystal-lang
blackchalk has quit [Changing host]
blackchalk has joined #crystal-lang
blackchalk_ has joined #crystal-lang
blackchalk has quit [Ping timeout: 265 seconds]
blackchalk_ has quit [Client Quit]
<FromGitter>
<girng> @bew well, i was just thinking hashes are not as good as i thought then. if they are allocated on the heap, they just get GC'd but not truly free'd to the OS (crystal's memory usage will still stay the same). but if using namedtuples, since when allocated on the stack, they get free'd.
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter>
<girng> however, if they get free'd from the stack, is that memory released to the OS?
Yxhuvud has joined #crystal-lang
<FromGitter>
<bew> the stack has a fixed size
<FromGitter>
<girng> what's the size?
<FromGitter>
<bew> it's usually 8MB
<FromGitter>
<bew> iirc each fiber has a 4KB stack, that can be extended to 8MB maximum
<FromGitter>
<girng> @bew i see, so there is around `8388608` bytes in 8MB. and if my NamedTuple is duplicating 16 bytes per method call ⏎ the STACKOVERFLOW error would have to be triggered at a point where that method is being CALLED so faster, that it ultimately exceeds the `8388608` byte limit?
<FromGitter>
<girng> that would rarely happen with player base, especially since i have rate limiting. probably only happen if infinite loop so i should be ok
<FromGitter>
<bew> huh no, there is no such thing as "method being called so faster", speed can't affect anything here
<FromGitter>
<girng> why is there a limit in the stack then?
<FromGitter>
<girng> @bew so in my example code there is no memory leak. the NamedTuple just jams it up the stack, get's freed, then crystals wait for another stack call? ⏎ where does the 16 bytes go, just get re-used by the next stack call?
qard has quit [Quit: qard]
bcardiff has joined #crystal-lang
qard has joined #crystal-lang
That_Guy_Anon2 has quit [Remote host closed the connection]
bcardiff has quit [Quit: bcardiff]
<FromGitter>
<bew> something like that yes (the stack memory and how it's used is very interesting though, you should have a deeper look about it one day :) )
Yxhuvud has quit [Read error: Connection reset by peer]
Yxhvd has joined #crystal-lang
<FromGitter>
<girng> morning
Yxhvd has quit [Read error: Connection reset by peer]
Yxhuvud has joined #crystal-lang
flaviodesousa has joined #crystal-lang
Groogy has quit [Disconnected by services]
Groogy__ is now known as Groogy
<Groogy>
Morning! 👋
Groogy2 has joined #crystal-lang
<Groogy>
oh @sdogruyol long time no see
<FromGitter>
<sdogruyol> oh, hey Groogy :)
<faustinoaq>
@sdogruyol Morning! Hey, how is going your book about crystal? :) I have no idea what topic choose for my undergraduate thesis, so I'm thinking on write a book about crystal WDYT?
<FromGitter>
<Sjoerrdd> morning
<FromGitter>
<bararchy> Morninggg
<FromGitter>
<bararchy> faustinoaq sounds cool :) the mroe the better I guess, can you dive to the languge internals or just syntax and basic usage?
<FromGitter>
<sdogruyol> @faustinoaq that'd be great :)
<FromGitter>
<sdogruyol> I'm halfway through the book 👍
<Groogy>
wow that went fast D:
<Groogy>
my book took months to finish
<FromGitter>
<sdogruyol> it's been a while Groogy :P
<Groogy>
ah true
<FromGitter>
<omerxx> Hi, anyway I can see the output of my `Process.run("bash command...")` ? ⏎ (Or is there a better way to run shell commands?)
<FromGitter>
<bararchy> @omerxx you can pipe stdout and stderr to pipes
<FromGitter>
<Sija> morning y’all!
<FromGitter>
<Sjoerrdd> Morning (:
<FromGitter>
<omerxx> @bararchy can you help? I'm not getting it. Tried `Process.run("export OMER=1", output: STDOUT)`
<FromGitter>
<Sija> @Sjoerrdd any framework you’re using?
<FromGitter>
<Sjoerrdd> Yes, Amber. ⏎ I allready asked it in the Amber group, but there are less people online
<FromGitter>
<omerxx> Guys, I can't seem to find Process.run in even in the source code. ⏎ Anyone can point out the right way to execute shell commands from Crystal code?
<FromGitter>
<bararchy> @omerxx let me try and help
<FromGitter>
<bararchy> give me a sec
<FromGitter>
<omerxx> @bararchy Awesome, thank you :)
<FromGitter>
<omerxx> @bararchy Actually I've been trying this, but the `output` stays an empty string no matter what I do. Will try a little more. Are you reading the output successfully?
<FromGitter>
<bararchy> which makes it much smaller
<FromGitter>
<bararchy> and also you don't really need IO for both error and output because we only care about if there is or isn't
<FromGitter>
<bararchy> so can use same IO for both
<FromGitter>
<bararchy> yuo can also ofc make the IO::Memory size smaller etc.. or bigger as you need
<FromGitter>
<omerxx> true. thanks a lot!!!
<FromGitter>
<bararchy> np :)
<FromGitter>
<bararchy> nice to see more ppl from Israel join the community ;)
ua__ has joined #crystal-lang
<FromGitter>
<omerxx> @bararchy Definitely!!
blackchalk has joined #crystal-lang
blackchalk has joined #crystal-lang
blackchalk has quit [Changing host]
<FromGitter>
<bararchy> if we get anymore we can open a Telegram channel :) ⏎ we got @Schniz also
ua_ has quit [Ping timeout: 240 seconds]
blackchalk has quit [Quit: quitting]
<FromGitter>
<omerxx> @bararchy I'm in... :)
<FromGitter>
<straight-shoota> @omerxx If you need help debugging the addrinfo issue, you can just ask here
<FromGitter>
<omerxx> @straight-shoota Thanks!
<crystal-gh>
[crystal] straight-shoota opened pull request #5943: Fix HTTP::ChunkedContent#peek return empty bytes at EOF (master...jm/fix/chunked-peek-empty) https://git.io/vxNOt
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter>
<omerxx> Guys, another question, When parsing a json with `JSON.parse` I'm getting a hash. But there's a nested json inside that is a `JSON::Any`. How can I extract values from this nested object? Is there a way to case it to a hash or something? ⏎ I don't want to do any string manipulations on it. ⏎ The object is ⏎ ⏎ ```{"key":"12345"}``` [https://gitter.im/crystal-lang/crystal?at=5acdf5fd270d7d3708b69e6d]
<FromGitter>
<straight-shoota> `JSON::Any` just wraps the internal values (like Hash)
<FromGitter>
<straight-shoota> you can use `#[]` to access it as a hash or `as_h` to unwrap the Hash
<FromGitter>
<omerxx> @straight-shoota How do I extract them then? hash-like reference (`object["key"]`) is not acceptable. The compiler says it's a string
<faustinoaq>
@straight-shoota There is some shorcut help for the new api search, I mean `s: search`, `up/down: select result` `space: go down`, `shift+space: go up`, What other shortcuts are available?
<FromGitter>
<straight-shoota> type `?` and you'll see =)
<faustinoaq>
Oh, excellent! :D
<FromGitter>
<straight-shoota> space doesn't work, though
<FromGitter>
<straight-shoota> ^^
<faustinoaq>
Are you sure? I'm using `space` and `shift+space` to go up and down right now :)
<faustinoaq>
Is pretty common shortcut in most browsers
<FromGitter>
<Sjoerrdd> shift+space
<FromGitter>
<Sjoerrdd> I didn't know that
<FromGitter>
<Sjoerrdd> thanks ;)
<faustinoaq>
@Sjoerrdd, yeah, some shortcuts has a `shift+` part to "revert" an action by example `shift+tab`, `shift+space`
duane has joined #crystal-lang
<FromGitter>
<straight-shoota> yeah, it's for scrolling in a browser pane
<FromGitter>
<straight-shoota> I thought you meant going through the results list
<FromGitter>
<straight-shoota> it's a browser feature, not specific to the API docs
duane has quit [Ping timeout: 264 seconds]
bcardiff has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
<FromGitter>
<girng> i like stack, but i also like hashes
<FromGitter>
<girng> but hashes use the heap.... so im not sure what to do
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
<FromGitter>
<sdogruyol> how's the difference? Have you benchmarked it yet?
<FromGitter>
<sdogruyol> (for your use-case ofc)
<FromGitter>
<girng> well,its not about performance per-say. it's about memory allocation. if i create a namedtuple it gets allocated on the stack AFAIK and then it get's free'd
<FromGitter>
<girng> but if i create a hash,it gets allocated on the HEAP? but then this memory goes to the GC, and doesn't get free'd to OS. i want to allocate on stack
<FromGitter>
<Sija> Any1 knows why this (https://carc.in/#/r/3uyi) ain’t working (see `FIXME` comment)?
lhz has quit [Quit: WeeChat 0.3.7]
<FromGitter>
<bcardiff> Because the compiler does not know @processor will be initialized by the map operation.
marius has quit [Quit: baj]
marius has joined #crystal-lang
<FromGitter>
<bcardiff> @Sija ahhh. got it. you are referencing self in the new
marius has quit [Quit: Ping timeout (120 seconds)]
<FromGitter>
<bcardiff> Since self is been passed out, there is no guarantee that the callee wont call methods that assume the callee was fully initialized, so every ivar that is not initialized before that call are assume nillable. hence, complaining.
marius has joined #crystal-lang
<FromGitter>
<Sija> spot on! thanks for explaining :)
snsei has quit [Read error: Connection reset by peer]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
marius has quit [Quit: Ping timeout (120 seconds)]
snsei has quit [Remote host closed the connection]
marius has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qard has joined #crystal-lang
marius has quit [Quit: Ping timeout (120 seconds)]
<FromGitter>
<girng> are arrays allocated on the stack?
<FromGitter>
<bew> no, Array is a class => allocated on the heap
<FromGitter>
<bew> StaticArray is a struct, allocated on the stack
<FromGitter>
<girng> thanks again =]
<FromGitter>
<bew> :)
<oprypin>
i sure hope the next question won't be "why is my code broken when I replace everything with StaticArrays"
<FromGitter>
<girng> nah was gonna ask a question about weakref :P
<FromGitter>
<girng> ima save that 1 forlater though
<FromGitter>
<girng> btw @ oprypin i upvoted 30 answers of yours on stackoverflow to show my appreciation of help
<FromGitter>
<girng> around 200 reputation i think, so thank you
<oprypin>
girng, yeah, i got a nice notification that serial voting was reverted, so you just put a tiny bad mark on my account
<FromGitter>
<girng> why they revert?
<oprypin>
because they don't support voting for a person, but voting for content
<FromGitter>
<girng> i was voting for your content of answers
<FromGitter>
<girng> they helped me
<FromGitter>
<girng> well, sorry about that then they should mark my account not yours in any event. i was just trying to show my appreciation, but whatever
<oprypin>
no, there's no consequence
<FromGitter>
<girng> that's re-assuring, i would think my account would get in trouble for doing that, glad yours is okay. apologize for the trouble there was just kind of giddy because you helped me and upvoted all your answers out of happyness
Liothen has quit [*.net *.split]
thunker[m] has quit [*.net *.split]
Liothen has joined #crystal-lang
Liothen has joined #crystal-lang
thunker[m] has joined #crystal-lang
salvor has quit [Ping timeout: 260 seconds]
salvor has joined #crystal-lang
benharri is now known as no_u
no_u is now known as benharri
benharri is now known as no_u
no_u is now known as benharri
bazaar_ has quit [Quit: Reconnecting]
bazaar has joined #crystal-lang
shalmezad has quit [Quit: Leaving]
duane has quit [Ping timeout: 263 seconds]
Vexatos has quit [Ping timeout: 256 seconds]
Vexatos has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]