YouTubevideo· Nov 22, 2024· 11:01
I always like seeing how the same app would be built in different text Stacks what choices would you make what are the things that make each individual text stack language uh options unique and Theo from t3.8 he built this roundest app uh which
basically is hey how can you rate a categories of Pokémon in which is round and it was built in let's see so this is one app five Stacks it was built in the react server components version there was a rails version a um OG T3 stack which I believe was the original application that Theo kind of built when
he put out his T3 stack tutorial and then an Elixir version as well as a go and graphql version and uh each one of these is really interesting I took a deep into the code to see like how each was kind of being built and there are some differences in terms of like the UI and like what the results page kind of looks like and how things are seated
versus how they're fetched on load and I figured why don't I do this with the tall stack with the stack that I am most familiar with lville Live Wire um we're not really using Alpine other than what Live Wire kind of gives you out of the box and then tailwind and and I basically tried to copy as much one for one as some of the other ones I basically I I took a lot of inspiration or just took a lot of the code from
rails cuz it's very similar as well as the Elixir version one thing that's really crazy to me and I haven't fully optimized my application that I'll show you in a little bit but the Elixir version is incredibly fast this is not turbo but still if I was to click I'm clicking really fast really fast really fast and it just it this this is live view you know web sockets in action even the turbo Turbo version I mean I can't
really tell the difference between both of them but that is definitely by far the fastest version that was built uh o GT3 stack is a little bit slower compared to the RSC version um that cold St is a little bit slow uh then you have rails version which I would say the tall stack at least how I built it initially and this is just kind of very basic I threw this together over a lunch break um it's probably around the same speed
maybe a little bit faster than the rails version RSD version is is fast um especially it doesn't let you kind of like click multiple times within because of what Live Wire is doing it does allow you to click multiple times um and then the uh go and graphql version is probably uh about the same speed as rails maybe a little bit slower just in terms of feel so what is
roundest the larel version round this. josh.com this is actually hosted on laravel cloud um so little sneak peek into uh how this is hosted I basically pushed it up to the GitHub repo and then hosted it on cloud and so this is the tall stack version um voting the first one is probably a little bit slower just uh but then after that it starts to
speed up a little bit you can tell it kind of has a little bit of lag behind like if I was to click it there's a slight delay and if you click multiple times I stopped and all of a sudden there there's a slight delay in terms of what it's catching up to because we're making those server requests we get all the information the UI just hasn't fully rendered the Sprites and so I think there are some optimizations that I can make within this in terms of maybe like
cashing the Sprite I did find Nick pots made a version of round this larel that I didn't see until after I had put together my version there are some differences in the code so why don't we dive into what uh Nick was doing and then I'll kind of put in how I did it a lot of how the uh Cedars is very similar so in the sense of the actual database and Cedars it's it's one database Cedar
that were pulling in all the Pokemon information again some of the apps within that the onea five stack thing some of them like rails had I believe the votes as another table I just kind of like left votes like elixir where votes were kind of in the same table I believe Nick pots has two different models yeah vote model and then a Pokemon model and this is where Nick
kind of got a little bit creative in terms of the speed in which this allows to be done and this is probably some of the optimizations that I can make in my application uh he fetches a specific count and then if we take a look at his line wire um the vote page which is the main page uh on Mount fetches to Pokemon
as well as the next 10 so what he's doing is he's pushing the next 10 uh into the into the page from the get-go so that way there's a little bit less uh a little bit less having to be fetched on every turn and you'll see how I'm doing it in a little bit but in the Live Wire views of vote what he's doing is he's prefetching the next 10 as the
Pokemon are continuously voted for uh and this is also interesting too the wire. replace self I I wonder if there's I wonder if that is a optimization I can make as well I actually haven't seen it too much yeah CU that's replacing the image for the Pokemon URL very interesting I actually didn't see that until until now let's let's
check wire replace self you can also instruct live are to replace the target element as well as all children very interesting okay let's go ahead and dive into uh my source code first off how many lines of code is it uh it's kind of like a little bit of an unfair but it's good to know okay how much is actually happening uh it looks like around 1,17 I forget the numbers for what like rails was but I would imagine this is similar to like the rails and elixir version I
didn't try to optimize for lines of code but let's go ahead and pull this up the big differences that I did within the uh Pokemon model was being able to get a random pair and again you might have seen there like I could have optimized the lines of Code by deleting the user models and deleting these migrations I don't necessarily need I have this get random pair as a static function to be able to pull in the Pokemon that I need
uh on the page load so I have basically in our web routes I have two routes a slash route an index route and a results route and so in the index. blade. PHP I'm using volt the functional component we have a placeholder to basically say okay as this page is loading let's go ahead and show a loading spinner there's a bunch of little things I'm just catching right here like layout I also have this weird thing in vs code where
uh I have to save without formatting otherwise this kind of HTML here uh doc block gets all wonky and so I'm basically just pushing the Pokemon in using get random pair so that when whenever this handle vote is called it refreshes the component and so no optimization is really being done right now we're just handling the vote based off of the Pokemon ID and then just
going from there same thing on the results page but I did add a little bit different items on the results page so I do have in round this the lville version the results is uh paginated as well as a searchable function I did notice in The Elixir version the results is very nice I might change the UI to look a little bit closer to this I'll keep the search
and pagination maybe I also just noticed in the web routes I need to Lazy load these because we're using the placeholder but we're actually not lazy loading these so I can go ahead and uh push this to make that change so get status get ad get commit lazy load full pages we'll push that and get it deployed awesome so the only other
interesting thing that I know that that is uh interesting within the context of looking at the different applications is how easy it is within laral to get Cedar information we can even use graphql as a query for right here and that's what I'm doing I'm just passing all this information I did choose to save uh the Dex ID and the Sprite so you can see here we basically saved the URL of a Sprite spr based off this GitHub user
content with the Dex ID uh different versions of this application chose to pull the Sprite on page load using the Dex ID so basically just saying here's the image URL and they're just changing the Dex ID on page load or when they're grabbing that I believe even Nick Potts is doing that as well maybe not Pokemon URL so it looks like he was saving the
URL for the Sprite some additional optimizations that I could make to make this a little bit better would be to have cached versions which saying okay let's cash the next 10 similar to like what Nick pots is doing so that when we're voting we're basically just uh voting and applying those changes using an array that we've already preloaded another thing that someone had mentioned within the comments of the one at five
stacks and a pull request is being able to have additional improvements for The Elixir version which included I believe pulling up let's load all the images up front instead of the only thing next to that's really interesting to me because that might be something that we could do within the tall stack basically just cach all the images and pull them on first page load so that we're just looping through those as you get to each individual index of a Pokemon all in all
it was a lot of fun being able to kind of dive in and just at least really quickly and we'll make some optimizations as we go but really quickly just see okay what what are the differences between some of these more popular Tech stacks and how do you make choices when it comes to loading information or you know making all of this happen and even some of the queries that I didn't fully talk about in terms of like the results page and basically I
just optimize or opted for the query builder in that instance of okay how are we calculating the percentage win so there's so many ways to do things so as long as you keep building and keep creating