<< 25-01-2025 >>

00:48:43*beholders_eye quit (Ping timeout: 264 seconds)
00:48:52*GnuYawk67 quit (Quit: The Lounge - https://thelounge.chat)
00:49:16*GnuYawk67 joined #nim
01:20:56*alexdaguy joined #nim
01:54:24*alexdaguy quit (Quit: w)
02:26:32FromDiscord<arkanoid> Hello! I have a general question about Memory Management. What is a cycle and why it hides in json and closures, why ORC succeeds in solving the cycles but ARC cant stop you from generating one?
02:29:42FromDiscord<Elegantbeef> Cause no one wrote a debug utility to report when a cycle was detected
02:30:05FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#pasty=lMQOPRMc
02:30:44FromDiscord<Elegantbeef> A cycle is just a self reference either directly or indirectly, which means you need a more elaborate de allocation method than RAII
02:31:13FromDiscord<albassort> In reply to @albassort "https://github.com/nim-lang/Nim/blob/8fe518ed47163e": beef can you confirm this is an error
02:31:59FromDiscord<Elegantbeef> As in what?
02:32:28FromDiscord<arkanoid> can a cycle be detected/prevented at compile time, or is it a run-time only experience?
02:32:42FromDiscord<Elegantbeef> It's only possible at runtime given how Nim types are
02:32:55FromDiscord<Elegantbeef> since a `ref` is not single ownership you can only assume whether a type is cyclical
02:33:04FromDiscord<albassort> in the event safe disconnect is present, it cnanot raise an exception. If it cannot write, to the socket, and cannot detect its disconnected because its deepcopied between threads, it can get stuck in the while loop, so it should break
02:33:16FromDiscord<Elegantbeef> Of course with ARC you can at least annotate `{.acyclic.}` on types where it's required
02:34:36FromDiscord<albassort> sent a long message, see https://pasty.ee/AMBJITjr
02:35:10FromDiscord<albassort> adding break stops it but doesn't really notify you of the error
02:35:15FromDiscord<albassort> (edit) "adding break stops it but doesn't really notify you of the error ... " added "or its disconnection"
02:35:20FromDiscord<Elegantbeef> Right you seem to be correct
02:35:29FromDiscord<albassort> the solution is to remove safe disconn but you have no way of knowing
02:35:58FromDiscord<Elegantbeef> With safe disconnect it'll dead lock in here if `isBlockingErr` is false
02:36:36FromDiscord<Elegantbeef> Quick someone say something witty like "Exceptions are flow control"
02:37:08FromDiscord<albassort> they are until they aren't, like all flow control concepts like... indentation
02:37:54FromDiscord<arkanoid> does it mean it only happens with GCed memory? Cycles cannot happen on stack because of forced copy semantics?
02:38:13FromDiscord<Elegantbeef> No cycles cannot happen on stack cause you cannot have a self referential type in safe nim
02:38:34FromDiscord<Elegantbeef> It only happens in closures and references as they're memory safe references
02:38:53FromDiscord<Elegantbeef> Also should note JsonNodes can be cyclical, but only if you explicitly make them such, which will explode on serialisation
02:40:23FromDiscord<arkanoid> I don't get then what is the meaning of the acyclic pragma. Is it just to make ORC skip the task for that type and save time, or can it also provide some more safety
02:40:31FromDiscord<Elegantbeef> It just means "I know this will never be cyclical"
02:41:21FromDiscord<Elegantbeef> It stops Orc and there are no safeties
02:41:27FromDiscord<Elegantbeef> Which is why it's used in JsonNode
02:44:29FromDiscord<arkanoid> I don't get your last line. Can't a JsonNode create a cycle?
02:44:52FromDiscord<Elegantbeef> Like I said you technically can, but it's a useless type
02:45:08FromDiscord<Elegantbeef> How do you serialise a cyclical json type?
02:46:41FromDiscord<arkanoid> maybe you never serialize and deserialize, but just create in memory and use it as internal data structure
02:46:50FromDiscord<Elegantbeef> Sure you could, or you could author your own data type 😄
02:47:04FromDiscord<Elegantbeef> But yes if you use it as a dynamic type you will leak if you have it self reference
02:47:22FromDiscord<Elegantbeef> That's again using the API wrongly and just abusing it's existence
02:47:28FromDiscord<arkanoid> thanks for all the answers
02:48:00FromDiscord<arkanoid> also thanks for the stack strings package. I'm using it and it's making my threading code easier to use
02:48:26FromDiscord<Elegantbeef> I only contributed to it 😄
02:49:41FromDiscord<arkanoid> best way to ensure my code is not using the heap? valgrind? instrumentation? panic in custom memory allocator? ask to the Delphi Oracle?
02:50:05FromDiscord<Elegantbeef> Replace `malloc` with a panic 😄
02:53:13FromDiscord<arkanoid> wow, I nailed it then \:D
02:53:30FromDiscord<Elegantbeef> Well it's the easiest way
02:54:20FromDiscord<Elegantbeef> Write your own allocator that you `LD_PRELOAD`, probably can even abuse Nim stack traces to get some useful information
02:55:40FromDiscord<arkanoid> https://stackoverflow.com/questions/48949265/how-to-develop-on-the-stack-with-nim
02:56:29FromDiscord<Elegantbeef> Actually since Nim exposes `allocImpl` you might be able to just change the pointer
02:57:06FromDiscord<albassort> sent a code paste, see https://play.nim-lang.org/#pasty=KfTXrVwS
02:57:08FromDiscord<albassort> boom reproduction
02:57:14FromDiscord<Elegantbeef> Ah nvm that's a procedure not a pointer
02:57:17FromDiscord<arkanoid> interesting. It seems that also gc\:None causes warning, so it may be sufficient to turn warnings into errors
02:57:31FromDiscord<Elegantbeef> The issue with no GC is you don't get destructors or hooks
02:57:37FromDiscord<Elegantbeef> So you're neutering your feature set
02:57:44FromDiscord<albassort> (edit) "https://play.nim-lang.org/#pasty=hyWvPVPO" => "https://play.nim-lang.org/#pasty=yJswBGId"
02:57:44FromDiscord<Elegantbeef> For something that truthfully isn't that important
02:58:26FromDiscord<Elegantbeef> Nice now make an issue or PR to fix it 😛
02:58:36FromDiscord<albassort> uhhhhhhhhhh
02:58:45FromDiscord<albassort> the easiest way is a timeout
02:58:53FromDiscord<arkanoid> oh, I thought that hooks and destructors were unrelated to gc\:None, but it actually makes sense
02:58:56FromDiscord<albassort> like 100 tries to send then you break and raise an error anyway
02:59:18FromDiscord<albassort> or find a better way to detect if its closed, but that seems complicated
03:00:53*mronetwo quit (Server closed connection)
03:01:01*mronetwo joined #nim
03:01:41*rockcavera joined #nim
03:02:51FromDiscord<Elegantbeef> Stop it
03:02:51FromDiscord<arkanoid> haha sorry
03:02:51FromDiscord<Elegantbeef> Get some help
03:02:53FromDiscord<Elegantbeef> The heap is not scary, whoever told you it was was smoking the good stuff
03:02:53FromDiscord<arkanoid> It is scary if you use threads
03:02:53FromDiscord<Elegantbeef> So then don't share heap resources across threads
03:02:54FromDiscord<Elegantbeef> So much easier than avoiding the heap all together and only using stack
03:02:56FromDiscord<Elegantbeef> Only using the stack is a path towards silliness
03:02:58FromDiscord<arkanoid> (safe) nim forbids you to do so. BTW am already doing that\: forcing stack only for thread shared data. I was only curious how much data I can put on the stack
03:03:00FromDiscord<Elegantbeef> It does not forbid you to
03:03:18FromDiscord<Elegantbeef> `isolate(T)` 😛
03:03:30FromDiscord<arkanoid> sure, it does. If you try to read GCed data from thread it doesn't compile
03:03:45FromDiscord<Elegantbeef> Emphasis on 'share'
03:03:56FromDiscord<Elegantbeef> Don't share resources = happy life
03:06:26FromDiscord<arkanoid> thread that does not share resources is the unsafe version of a process
03:06:38FromDiscord<Elegantbeef> How is that unsafe?
03:07:00FromDiscord<arkanoid> ask chrome developers and firefox developer
03:07:09FromDiscord<Elegantbeef> How can it be unsafe if there is no sharing
03:07:34FromDiscord<Elegantbeef> It's even safer as it requires no mutexs
03:09:18FromDiscord<Elegantbeef> You run the code to completion and wait for your threads to finish then get the values
03:09:21FromDiscord<Elegantbeef> Threadpools are not unsafe
03:10:30FromDiscord<arkanoid> because if anything goes out of control it your thread, it can peek into the heap (firefox issues)
03:10:44FromDiscord<arkanoid> because if anything goes out of control in your thread, it can peek into the heap (firefox issues)
03:10:47FromDiscord<Elegantbeef> That happens without threading
03:11:16FromDiscord<Elegantbeef> Buffer overflows are not the reserved for threading
03:11:37FromDiscord<arkanoid> with processed you are much safer in same condition
03:11:44FromDiscord<arkanoid> with processes you are much safer in same condition
03:12:03FromDiscord<Elegantbeef> Except processes have startup time and require multiple binaries
03:12:12FromDiscord<Elegantbeef> Unless you embed it all into a single binary then load it up
03:13:06FromDiscord<Elegantbeef> You should avoid sharing between threads anyway, just cause you can does not mean you should multiple your scope of mutable state
03:15:53FromDiscord<arkanoid> if all you need is performance, yes that's the defensive strategy. Else, it's process isolation intrinsic job
03:16:40FromDiscord<Elegantbeef> So we've got you down to spawning a process instead? 😄
03:17:58FromDiscord<arkanoid> even better! My program is running threads that are spawning multiple processes!
03:19:39*adigitoleo quit (Ping timeout: 248 seconds)
03:21:49*adigitoleo joined #nim
03:24:05FromDiscord<arkanoid> I just realized that I'm asking about stackoverflow on stackoverflow. Interesting
03:27:48FromDiscord<arkanoid> it seems that the limit for the main thread stack size is 512KB on Mac, 1MB on Windows and 8MB on Linux. Non main threads have a lower stack limit that seems to depends on the api used on each platform
04:05:39FromDiscord<leelikesfries> this language is absolutely beautiful
04:22:24FromDiscord<albassort> In reply to @leelikesfries "this language is absolutely": Nim or English 😛
04:23:54FromDiscord<albassort> you know fucking what
04:24:08FromDiscord<albassort> i bet that socket bug is the exact bug that i've been complaining about for like 4 years
04:24:22FromDiscord<albassort> with threaded httpclient instances
04:26:23FromDiscord<Elegantbeef> I don't know if sending Sockets across threads is a faux pas or not
04:29:58FromDiscord<albassort> well, i need to, its not in my context
04:30:07FromDiscord<albassort> now, if i should reconstruct the fd or not is up for debate
04:30:13FromDiscord<albassort> im not sure how i would keep it open with doing that
04:32:57FromDiscord<Elegantbeef> I imagine that'll be what's suggested
04:55:53*robertmeta quit (Server closed connection)
04:56:01*robertmeta joined #nim
05:27:03*GnuYawk67 quit (Quit: The Lounge - https://thelounge.chat)
05:27:21*GnuYawk67 joined #nim
05:45:53*ursa-major quit (Server closed connection)
05:46:02*ursa-major joined #nim
06:16:53*bgupta quit (Server closed connection)
06:17:02*bgupta joined #nim
06:39:56*coldfeet joined #nim
08:55:49*ntat joined #nim
09:19:17FromDiscord<michael.lenz.> sent a code paste, see https://play.nim-lang.org/#pasty=HVCUzTWu
09:23:39FromDiscord<michael.lenz.> There’s better implementation with use of channels by Elcritch. So it’s not works because of gc, and ref type of the socket
09:30:34*ntat quit (Quit: Leaving)
09:41:47FromDiscord<michael.lenz.> Here are code examples https://github.com/nim-lang/Nim/issues/24591
10:55:43FromDiscord<albassort> In reply to @michael.lenz. "I had the same": doubt this is the same issue
10:56:22FromDiscord<albassort> https://github.com/nim-lang/Nim/issues/24648
11:15:26FromDiscord<michael.lenz.> In reply to @albassort "doubt this is the": It should be. As I understood you have issue with passing the socket to te thread using channels
11:16:19FromDiscord<albassort> pretty sure the issue is the deepcopy of the socket
11:16:30FromDiscord<albassort> if the issue is the same, my suggeted fixes should work on your code
11:16:32FromDiscord<albassort> go ahead and see
11:19:44FromDiscord<michael.lenz.> Sure, I will check it out when I get back
11:22:21FromDiscord<michael.lenz.> I see now what’s the difference, ok
11:23:32*beholders_eye joined #nim
11:25:29FromDiscord<michael.lenz.> And what if you store client socket as in separate array element and try to pass via channels to te thread?
11:38:23*oisota quit (Server closed connection)
11:38:40*oisota joined #nim
11:39:00*beholders_eye quit (Read error: Connection reset by peer)
11:45:59FromDiscord<michael.lenz.> The deepcopy should not cause this. More like it’s because thread opeates with the client socket in parallel, and accept modifies it at the same time on next connect event. I will check the code when I go back home
11:46:23*alexdaguy joined #nim
11:47:16*beholders_eye joined #nim
11:57:22*beholders_eye quit (Quit: WeeChat 4.1.2)
11:57:38FromDiscord<albassort> In reply to @michael.lenz. "The deepcopy should not": its def not this
12:00:25*beholders_eye joined #nim
13:05:23*xet7 quit (Server closed connection)
13:05:47*xet7 joined #nim
14:52:18*alexdaguy quit (Quit: w)
14:58:51FromDiscord<michael.lenz.> In reply to @albassort "its def not this": Plese check the comment, the issues is with accept(), because the call is blocking
15:24:20FromDiscord<leelikesfries> sent a code paste, see https://play.nim-lang.org/#pasty=uufPBTtB
15:28:14FromDiscord<odexine> https://nim-lang.org/docs/tables.html#getOrDefault%2CTable%5BA%2CB%5D%2CA%2CB
15:59:31*ntat joined #nim
16:25:03FromDiscord<firasuke> So how do you compute sha256 of a file using constantine? https://github.com/mratsim/constantine
16:27:22rockcaverafirasuke see https://github.com/mratsim/constantine/blob/master/tests/t_mac_hmac_sha256.nim
16:27:23FromDiscord<firasuke> I tried using one of the libraries here: https://github.com/mratsim/constantine/tree/master/constantine/hashes/sha256
16:27:27FromDiscord<firasuke> but was unsuccessful
16:27:52FromDiscord<firasuke> In reply to @rockcavera "firasuke see https://github.com/mratsim/constantine": ok
16:28:21rockcaveraor https://github.com/mratsim/constantine/blob/master/tests/t_hash_sha256_vs_openssl.nim
16:31:09FromDiscord<firasuke> In reply to @rockcavera "or https://github.com/mratsim/constantine/blob/mast": already checked that
16:35:08FromDiscord<firasuke> still thanks
16:41:26rockcaverafirasuke https://play.nim-lang.org/#pasty=MqRbiDWX
16:49:44FromDiscord<firasuke> In reply to @rockcavera "firasuke https://play.nim-lang.org/#pasty=MqRbiDWX": cool, thanks
16:52:02rockcaverafirasuke https://play.nim-lang.org/#pasty=HRtOHYnk if you are going to read the file little by little, you need to do it this way with `update()`
17:33:12FromDiscord<leelikesfries> In reply to @odexine "https://nim-lang.org/docs/tables.html#getOrDefault%": i really love nim.
18:15:15FromDiscord<firasuke> In reply to @rockcavera "firasuke https://play.nim-lang.org/#pasty=HRtOHYnk ": sure
19:24:55*SchweinDeBurg quit (Read error: Connection reset by peer)
19:30:21*SchweinDeBurg joined #nim
20:25:46FromDiscord<System64 ~ Flandre Scarlet> Hi, is there a library to manipulate WAV files please?↵especially to get the samples
20:26:52FromDiscord<michael.lenz.> In reply to @sys64 "Hi, is there a": libsndfile
21:43:54strogon14https://github.com/SpotlightKid/nim-sndfile
21:46:51strogon14The original author gave me permission, to replace his version with mine at nimble.directory, but I haven't done a PR to update the entry yet. I wanted to add more tests first, but I should probably just release the damn thing.
22:33:03*ntat quit (Quit: Leaving)
22:48:44*marcus quit (Remote host closed the connection)
22:50:34*marcus joined #nim
22:50:37*coldfeet quit (Quit: Lost terminal)
22:53:59*marcus quit (Remote host closed the connection)
22:55:45*marcus joined #nim