<leftylink>
I have not heard that name in a long time
<al2o3-cr>
et09: just remember this, in a method defintion `def foo(&block)` in this instance the `&` means convert a block of code to a proc (a procedure). But, foo(&bar) means pass the proc (prodecdure) as a block.
<al2o3-cr>
as a block of code
<al2o3-cr>
et09: the only reason to use the &block syntax is if, for e.g saving the binding to a variable and use it later somewhere in your code.
<al2o3-cr>
&>> class Foo def initialize(&b) @b = b end; def shout() @b.call.upcase end end; Foo.new { 'foo' }.shout
<rindolf>
need to move forward if they want to upgrade Rails (and culturally, they normally do)" ; the docker instructions failed on my debian bullseye partition too (and failed earlier on fedora 33 with podman).
BenDover has joined #ruby
BenDover has quit [Client Quit]
rippa has joined #ruby
BenDover has joined #ruby
gix- has quit [Ping timeout: 246 seconds]
Besnik_b has quit [Quit: Ika]
dfucci has joined #ruby
<jhass>
rindolf: not too much, 2.7 has been quite noisy on the deprecation warnings towards Ruby 3, so people sticked to 2.6 more :)
Swyper has quit [Remote host closed the connection]
Swyper has joined #ruby
Swyper has quit [Remote host closed the connection]
Besnik_b has joined #ruby
dionysus69 has joined #ruby
weaksauce has quit [Ping timeout: 240 seconds]
dionysus69 has quit [Ping timeout: 240 seconds]
roadie has joined #ruby
TzilTzal has quit [Ping timeout: 246 seconds]
Swyper has joined #ruby
Besnik_b has quit [Quit: Leaving]
Swyper has quit [Ping timeout: 260 seconds]
arkinor has quit [Ping timeout: 240 seconds]
TzilTzal has joined #ruby
ivan_ has joined #ruby
<ivan_>
Hello
ivan_ has left #ruby ["Ciao!"]
dhollinger has quit [Ping timeout: 260 seconds]
dhollinger has joined #ruby
DaRock has quit [Read error: Connection reset by peer]
DaRock has joined #ruby
Technodrome has joined #ruby
phaul has quit [Ping timeout: 240 seconds]
rubydoc has quit [Ping timeout: 260 seconds]
roadie has quit [Ping timeout: 260 seconds]
phaul has joined #ruby
rubydoc has joined #ruby
ellcs has quit [Ping timeout: 272 seconds]
roadie has joined #ruby
ellcs has joined #ruby
TCZ has joined #ruby
BenDover has quit [Remote host closed the connection]
TzilTzal has quit [Quit: Leaving.]
ellcs has quit [Ping timeout: 272 seconds]
GodFather has joined #ruby
phaul has quit [Ping timeout: 240 seconds]
rubydoc has quit [Ping timeout: 246 seconds]
phaul has joined #ruby
rubydoc has joined #ruby
rubydoc has quit [Remote host closed the connection]
rubydoc has joined #ruby
BenDover has joined #ruby
Swyper has joined #ruby
titanbiscuit has quit [K-Lined]
stnly has quit [Quit: goodbye]
Swyper has quit [Remote host closed the connection]
Swyper has joined #ruby
akem has joined #ruby
fercell has joined #ruby
Besnik_b has joined #ruby
Guest25513 has quit [Quit: Leaving]
Besnik_b has left #ruby ["Po dal ca…"]
roadie has quit [Ping timeout: 272 seconds]
Swyper has quit [Remote host closed the connection]
cow[moo] has joined #ruby
meinside has quit [Quit: Connection closed for inactivity]
GodFather has quit [Ping timeout: 264 seconds]
stnly has joined #ruby
lucasb has joined #ruby
GodFather has joined #ruby
GodFather_ has joined #ruby
cow[moo] has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
skyikot has quit [Ping timeout: 240 seconds]
et09 has joined #ruby
impermanence has joined #ruby
DaRock has quit [Ping timeout: 260 seconds]
TCZ has quit [Quit: Diabe? tkwi w szczegó?ach]
helpa has quit [Remote host closed the connection]
helpa has joined #ruby
roadie has joined #ruby
adu has joined #ruby
GodFather_ has quit [Ping timeout: 272 seconds]
GodFather has quit [Ping timeout: 272 seconds]
adu has quit [Quit: adu]
baojg_ has quit [Remote host closed the connection]
baojg has joined #ruby
ChmEarl has joined #ruby
rubydoc has quit [Remote host closed the connection]
skyikot has joined #ruby
rubydoc has joined #ruby
TCZ has joined #ruby
ua has quit [Ping timeout: 256 seconds]
cow[moo] has joined #ruby
Technodrome has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ua has joined #ruby
execat[m] has joined #ruby
vondruch has quit [Read error: Connection reset by peer]
AndreYuhai has joined #ruby
seydar has joined #ruby
<AndreYuhai>
Hey there, is there anything wrong with overriding initialize in ActiveRecord::Base and then calling super? I am not sure whether I should do it or not. Some sources say not.
<seydar>
do ruby's blocks exist in other languages?
<adam12>
AndreYuhai: I'd stick with using after_initialize, imho.
<AndreYuhai>
adam12, then it doesn't really make sense to try to parse the data inside the class that inherits ActiveRecord::Base, right?
<adam12>
AndreYuhai: Not sure I follow.
<AndreYuhai>
adam12, So, let me show you an example
<jhass>
seydar: couple. Very directly in Crystal as it's deeply inspired. Groovy has something very similar, Kotlin too. I believe Swift too. Then you have a lot on the a little more explicit side, where you have a short and nice way to pass an anonymous function as an argument
<seydar>
jhass: thank you, it's tough to find lists on the web that distinguish between ruby-style blocks and, like you said, simply passing an anonymous function
<seydar>
jhass: i'm convinced the secret to ruby's ease and clarity is its blocks
<AndreYuhai>
adam12, not really show but explain, since there's not much to show. So let's say I have a class that inherits from ActiveRecord::Base, I should pass a hash to initialize the variables. But let's say first I want to parse an HTML document and then create a hash to pass to my database class. So I was trying to parse that HTML document inside the db class
<jhass>
I follow, but I wouldn't nail it down on the implicitness of the syntax, that they're closures plays an as big if not bigger role I think
<AndreYuhai>
adam12, but while I was writing I realized that that doesn't really make sense :D
<jhass>
also important is the strong emphasis stdlib puts on them
<adam12>
AndreYuhai: Maybe you want your own constructor that then calls `new`
<AndreYuhai>
adam12, oh that's what I will have to do I guess. Thank you!
moldorcoder7 has quit [Quit: %bye mirc%]
<seydar>
jhass: true: can't have method-ending blocks without closures in the first place
<seydar>
jhass: i'm always frustrated that python only allows single-line anonymous functions. i dislike having to define larger closures as a separate method and then passing those along
<jhass>
it's a cultural thing greater than that. Ruby and its community likes implicitness, convention over configuration. Python and its community tends to prefer explicitness, configuration over convention
<jhass>
compare django and rails, it's quite apparent
<nakilon>
my Ruby program has a huge Array that grows up to 2gb of RAM and then such operations as .sort and .uniq on it become too slow, so I moved this part to an external Go process that I start and kill when needed
<jhass>
maaaybe wrong data structure?
<nakilon>
I start it via popen3 and move data in both directions serialising it with Oj gem -- this reduced the amount of RAM and made possible to optimize those pieces of code about sort and uniq
<nakilon>
but the speed in the end is now 3 times lower and there is benchmark https://i.imgur.com/fpNJNw0.png -- 2/3 of times is gone for popen IO and Oj -- are there any better alternatives?
<jhass>
it's hard to judge given you talked about implementation but zero about the problem domain
<jhass>
but my first questionmarks would be, is array really a fit datastructure for the job? Is Ruby a fit tool for the job?
<nakilon>
jhass, if that question was addressed to me then unfortunately there are no better data structures I'm aware about for my program, since I'm already optimizing it for like two weeks
<jhass>
I mean given .uniq and .sort is your pain points SortedSet comes to mind, but as pointed out for a real recommendation the problem domain would need to be known much better
<jhass>
maybe there's an algorithmic solution that doesn't even require holding this much data in memory
<jhass>
it's really hard to give advice on this shallow info
<nakilon>
jhass, 1. it's not just an array, it's a mix of an array and map in golang already
<nakilon>
jhass, 2. if I was not doing it in Ruby I would achieve the same progress only in a year ) now after I'm pretty sure there is nothing huge to optimize algorithmically I'm doing this stuff around the satellite process, and at first I believed it would help but see the profiler report
<nakilon>
I'm not asking you to improve the algorithm -- I've already spent two weeks on it, and partially did it 5 years ago -- it can't be optimized by just a talk in IRC
<jhass>
how many LOC are we talking?
<nakilon>
the question is in the way I move data between two processes
<nakilon>
75 in Ruby, 70 in Go
<jhass>
and how production critical / stable does this need to be? does your buisness stand or fail on it?
<nakilon>
it's a solver for a competitive logical puzzle and there is an input case that to find the best solution for it eats >2gb of RAM and it becomes too slow to solve another dozen of such in adequate time
<jhass>
Okay, then if I were you I would invest a day to see if you can port it to Crystal (whole, without going through Go part)
<nakilon>
the puzzle is supposed to be solved by hand and I'm a cheater, yeah ) but I don't participate in daily competition rankings so I don't ruin others' fun
<jhass>
regardless I can't stop the feeling that a 2GB array you call .sort and .uniq on really should be a different purpose based data structure, something like a custom binary search tree or so
<jhass>
in any language
<nakilon>
I won't say "in any language"
GodFather_ has joined #ruby
<nakilon>
in Ruby it can be faster to aggregate and apply .uniq and .sort rarely and in parts, rather than doing microoptimizations, such as custom data type
<jhass>
a custom data type is by no means a microoptimization, generally
<jhass>
of course there's problems where it is
<nakilon>
after I moved this stuff out to Go it made me possible to change the .uniq call to adding to an array only if the item is uniq -- that won't be faster with Ruby stdlib in any way
<jhass>
Set?
<jhass>
or as said previously, SortedSet
<nakilon>
a million of Set.include? lookups is slower than a million of push and then uniq
<nakilon>
there is no need in SortedSet
<jhass>
only in Ruby though, because of the method call overhead
<jhass>
hence my suggestion to port to Crystal
<nakilon>
the .sort was needed for a correct .uniq procedure to throw out correct one from the pair
<nakilon>
after a move to Go the whole need in sort is gone
<jhass>
or just move to Go fully given you're already halfway there
<nakilon>
I don't sort it in Go, because in Go I do the "set.include?"-like thing and solve the collision for each push with no perfomance overhead
GodFather has joined #ruby
<nakilon>
oh, I won't say it's halfway -- converting it from Ruby to Go is making 10 times more lines of code
moldorcoder7 has joined #ruby
<jhass>
Did you take a look at Crystal yet? ;)
<jhass>
anyways, I'll stop now. You asked for opinions, you got mine. Take it or leave it.
<jhass>
There won't be a magic bullet to make your approach 10x faster than it already is
jottr has joined #ruby
<seydar>
jhass: my opinion is that these attitudes derived from the syntax and the opportunities presented by it (the ole "syntax changes the way you think" argument)
<nakilon>
I asked if there is a more efficient way to move data between two processes ..D
<jhass>
and I recognized it as a classic X/Y question :)
<jhass>
seydar: it's hard to separate. Yes mindsets get formed, or better strengthend, by it but it also attracts already compatible mindsets which then also have an influence how everything, including new syntax features, is designed
cer0 has joined #ruby
<jhass>
seydar: we observe this quite interestingly over at Crystal, which attracts the Ruby kind of folk based on its inspiration from it, but also another group looking just for a high-level compiled language coming from all other kinds of backgrounds. It actually leads to a lot of discussions over implicitness vs explicitness
cthulchu_ has joined #ruby
davispuh has joined #ruby
<summerisle>
I like crystal, but the strict type system can be a bit suffocating at times
TCZ has quit [Quit: Diabe? tkwi w szczegó?ach]
helpa has quit [Remote host closed the connection]
helpa has joined #ruby
Swyper has joined #ruby
drincruz has joined #ruby
Technodrome has joined #ruby
dfucci has quit [Ping timeout: 260 seconds]
cognemo_ has quit [Ping timeout: 272 seconds]
seydar has quit [Quit: leaving]
cognemo has joined #ruby
<nakilon>
by my estimation my solver will consume up to 8gb of RAM to find the optimal solution; benchmarking on simplier test cases the ruby+go would consume two times less RAM but it's several times slower because of the communication process
BTRE has quit [Remote host closed the connection]
Technodrome has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
pwnd_sfw9 has joined #ruby
Swyper has quit [Remote host closed the connection]
pwnd_sfw has quit [Ping timeout: 264 seconds]
pwnd_sfw9 is now known as pwnd_sfw
dfucci has joined #ruby
Swyper has joined #ruby
<apotheon>
nakilon: What do you mean "two times less"?
<apotheon>
Is that half as much RAM, or what?
<nakilon>
apotheon yes, sorry for bad English
<apotheon>
Thanks for clearing that up.
<nakilon>
ruby solution was like 30mb; ruby+go was like 20+9, where 20 obviously contains json garbage what would be cleaned by GC when needed; also even empty programs consume few megabytes so it should be subtracted too
<apotheon>
I'm not sure there's much you can do about the time spent in interprocess communication except by reducing the amount of interprocess communication.
<nakilon>
today I made two memory optimizations and maybe the solution will be found in the next hour but it's just a one puzzle case and other from the same difficulty range can be worse
<nakilon>
apotheon, tried that -- today's optimization have reduced json string size by x1.5, but the total time remained the same, not sure why
<nakilon>
also thinking about writing not line by line but making a multiline buffer but not sure if it will help
<nakilon>
should reduce the number of Oj and IO calls but the question is if the slow part is the call itself or not
roadie has quit [Ping timeout: 264 seconds]
<nakilon>
also I measure the total time used using "time" command line utility and that does not tell me which part of the CPU time was spent by Ruby and which by Go
<apotheon>
I doubt buffering would help overall speed much unless you're overwhelming available RAM or you're loading from disk while sending between processes or something like that.
<apotheon>
In the "from disk" case, the bottleneck is likely just disk I/O.
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
<nakilon>
you mean swap?
<apotheon>
Swap would be a consequence of overwhelming RAM.
<nakilon>
my json pieces are 1000-1500 bytes long; in that profiler screenshot there are 300'000 .write calls for a puzzle of 7'000 array items (i.e. pieces) in peak; in the case I try to solve there are >800'000 items already, so it's like 300mln of Oj and IO write calls
<apotheon>
I don't know where your Go process is getting its data before sending it to Ruby. Is it reading from disk?
<apotheon>
Actually, even worse than disk I/O would be over the network. That tends to be a bottleneck everywhere a network is connected to what people are doing.
<nakilon>
Go process is a storage for Ruby process, launched with popen3
<nakilon>
no network
<nakilon>
a single macos machine
Swyper has quit [Remote host closed the connection]
<nakilon>
so 300mln cycles is like... 500gb of json strings searialised and deserialised on both sides ..D that's what I pay by ruby+go solution to reduce the solution of a pure ruby process that otherwise eats almost 5gb of RAM already
<nakilon>
an observation that I already had earlier with other programs: if ruby process reaches 4gb RES it starts going back and forth between 3gb and 4.5gb with almost no computational progress; I feel like it's either Ruby's GC or OS hardcoded RAM treshold
ur5us has joined #ruby
dfucci has joined #ruby
ur5us has quit [Client Quit]
adu has joined #ruby
TomyWork has quit [Quit: Leaving]
Technodrome has joined #ruby
BSaboia has quit [Quit: This computer has gone to sleep]
<jhass>
AndreYuhai: **options expects keyword arguments, so .new(somehting: value), or .new(**some_hash)
<AndreYuhai>
jhass, so do keyword args not get passed as a hash?
<jhass>
right
<jhass>
at least semantically
<jhass>
especially towards Ruby 3 the differentation is made stronger
<AndreYuhai>
So what's the difference really I mean you use them both as a hash inside the function. Can I see how they are passed in some source code?
<jhass>
the entire point of ** is to convert between hash and keywords, the same way as * converts between array and arguments