Better HN
topnewbestaskshowjobs
Log inSign up

pat_shaughnessy

426 karma · joined Apr 4, 2011 (15y ago) · 81 submissions

Boston based Ruby developer: http://patshaughnessy.net and @pat_shaughnessy
Submissions

comment 1y ago · link · parent

That's the magic of YJIT, and what I'll describe in the rest of Chapter 4. YJIT uses a "wait-and-see" approach, and often defers compilation of the block/function until the actual types are provided by your program. And YJIT then keeps track of separate block versions based on the operand types, and can call the appropriate block version as needed.

This basic algorithm is called "Basic Block Versioning." Maxime Chevalier-Boisvert from Shopify has some great presentations online about this; for example [1].

I believe ZJIT, the newer JIT engine, uses a different approach. I'm exploring that now.

[1] https://www.youtube.com/watch?v=zO9_uTaELCw — RubyConf 2021 - YJIT - Building a new JIT Compiler inside CRuby by Maxime Chevalier Boisvert.

comment 1y ago · link · parent

> Idiomatic Ruby uses blocks for loop bodies

Yes that's something I want to dig into and explore in this chapter... when exactly does Ruby's JIT compiler activate and optimize our code? And you're right: since Ruby will JIT blocks as if they were separate function many loops will be optimized using this simple heuristic.

comment 1y ago · link · parent

What a lovely comment - thank you!

comment 10y ago · link · parent

I tried that while researching the article, but found the call to "puts" doesn't link without the standard library code. And without a "puts" or similar call to produce output LLVM optimized the entire program away :)

I suppose this could work if, as you suggest, I manually called out to a lib_c function like printf instead.

comment 10y ago · link · parent

(author here) ...FYI I actually learned assembly language for the first time back in the 1970s and 80s using a 6809 inside a Radio Shack "Color Computer." I was super-fun at the time. I don't remember much of it now but I'm sure x86 isn't as clean or fun as 6809 assembly was.

comment 10y ago · link · parent

Thanks a lot. I'm looking forward to writing it, I think it will be interesting.

comment 10y ago · link · parent

Thanks! Glad to hear you made it to the bottom :) I always worry that I tend to write on and on for too long.

comment 10y ago · link · parent

Thank you! Knowing that people enjoy reading this sort of thing makes it worthwhile.

comment 10y ago · link · parent

Thanks everyone for the kind comments, and for taking the time to read this stuff :)

comment 12y ago · link · parent

Yes, good point. Rails has a lot of conventions like this - that "first" implies ordering by primary key (by default). I just imagine that most Rails developers don't think about sorting and its implications when they ask for the first record.

comment 12y ago · link · parent

Oh absolutely. I thought about saying that, and just ran out of energy before posting the article this morning.

The reason I used this particular SQL statement as an example is that ActiveRecord (a Ruby ORM) generates it from a fairly simple, common Ruby expression. I suppose ActiveRecord could be improved to drop the sort when you know there's one one possible match.

comment 12y ago · link · parent

By the way, I used a simple query on purpose to keep things simple for readers (and for me, the author!). By using such a simple SQL statement I was able to avoid complex optimizations and algorithms I would haven't been able to follow - and that wouldn't have helped readers much anyway. I wanted to get the basic idea across to people who have no prior knowledge of DB internals.

Plus I wasn't interested in comparing one DB vs. another, as much as I was interested in understanding how any DB works.

comment 12y ago · link · parent

This sounds fascinating - I read Codd's original paper on relational algebra for my last post (http://www.seas.upenn.edu/~zives/03f/cis550/codd.pdf).

... and this notation almost seems more similar to the underlying math than SQL does.

comment 12y ago · link · parent

Thanks :) Yea indexes are where some of the real "magic" of database servers happens. It will be fun to write that up...

comment 13y ago · link · parent

I discuss circular references and how CPython handles them a bit in my followup post: http://patshaughnessy.net/2013/10/30/generational-gc-in-pyth...

16.

Expanded Ruby Under a Microscope Available in Print(patshaughnessy.net ↗)

7 points · by pat_shaughnessy · 13y ago · discuss

comment 13y ago · link · parent

Another great post, Daniel... keep 'em coming!

comment 13y ago · link · parent

I agree with the other commenters - RailsApps is a fantastic resource for the community. It's a great way to have a peer reviewed and curated set of high quality examples to learn from.

At the same time, I do agree with many of the points in Tammer's article. I think the danger with Rails templates, scaffolding and even Daniel's work is that it's very easy to take it and use it part and parcel without understanding what's really going on inside, and why certain decisions were made (this gem vs. that gem, or this code technique vs. that). I think there's a lot of value in starting from scratch (Daniel's option #1) and adding things step by step. As Tammer pointed out, this can lead to a positive team discussion and learning dynamic. And I don't mind the extra typing and time required.

The next time I start a new Rails app, I'll probably: - Look for a good example to learn from in RailsApps or elsewhere. - But then step back to "rails new" and add in the recommended gems bit by bit, with testing along the way. - Hopefully contribute back to RailsApp if I learn anything new :)

19.

Surprising performance results creating various Ruby primitives(patshaughnessy.net ↗)

1 points · by pat_shaughnessy · 13y ago · discuss

20.

The "Magic" behind AngularJS Dependency Injection(alexrothenberg.com ↗)

9 points · by pat_shaughnessy · 13y ago · discuss

21.

Sessions: The vim Feature You Probably Aren't Using(weblog.bocoup.com ↗)

2 points · by pat_shaughnessy · 13y ago · discuss

comment 13y ago · link · parent

Yup, (re)reading SICP is definitely on my list!

comment 13y ago · link · parent

Awesome links - thank you!

comment 13y ago · link · parent

Thanks! Yea for some reason learning how things work is often more satisfying to me than building stuff... I guess I'm more of a scientist than an engineer?

comment 13y ago · link · parent

Interesting idea - thanks for the suggestion!

comment 13y ago · link · parent

Absolutely - it is a pleasure to read. Someday I'd like to learn how another language is implemented, maybe JavaScript or something like Haskell, but I'm afraid the language source code will be much more difficult to understand than Ruby's is.

comment 13y ago · link · parent

I agree - it's an amazing narrative of an interesting time. I wonder if contacting Xerox directly would lead to some more historical archives?

comment 13y ago · link · parent

Thanks Gary... yea and all of these things more or less mean the same thing.

At a more technical, detailed level, however, the Ruby core team uses both the term "metaclass" (in the same sense Smalltalk uses it - the class of a class), and the term "singleton" (the hidden class of a single object instance). You can see what I mean by looking through the MRI class.c source file.

comment 13y ago · link · parent

Yea it's been a source of discussion (and confusion) for years. Thanks for the link!

comment 13y ago · link · parent

Great read - thanks! I love the river metaphors. The metaphysics discussion also brought back memories of college philosophy classes on Plato's theories around ideas vs. forms. Probably my memory is failing me here and someone more versed in philosophy could help me out here :) But to me it's interesting how classical philosophy could even remotely be related to computer programming.
123