All threads / GoRails Performance - The Techniques I Use Discussion
Ask A Question


You’re not receiving notifications from this thread.

GoRails Performance - The Techniques I Use Discussion

Itzik Ben Hutta ·

Thanks Chris. The first time my name appears on a video :)

Thanks for episode Chris. But what happens when turbolinks mess up and do not let your javascript code run when you "change" page? because i have had these issues here and there and i had to do something like data-no-turbolink.

Hey Pete, this usually happens from one of two things:

1. You're using a third party library (like for example) that isn't compatible with Turbolinks events by default. These usually require some tweaking in order to make compatible. It all depends on the library but there are usually ways to do it. You can google for that library + turbolinks and see if anyone else has made it work, or if you can tweak it yourself.

2. Sometimes it can just be a simple setup issue if your JS is running incorrectly. Maybe you need the jQuery.turbolinks adapter, or just to modify your code slightly to allow running on multiple pages.

It all kinda depends on your code and the issues you're experiencing. They can be kinda hard to track down so the easy solution is to turn off turbolinks for those links in the meantime if you can figure it out. I don't think there's anything wrong with that so you can figure it out later.

Hey Chris, thanks for getting back to me.

Well mostly the problem is with external libraries to be honest. Guess data-no-turbolink seems easier than trying to find a solution each time. But maybe its high time i do that.

I've found that using for managing those external libraries helps a lot. It makes that management a lot easier, but I also intentionally use very few third-party Javascript libraries because they can quickly slow down the frontend performance of a site. You might check out Segment and see how it goes.

Great insight! Though now I'm really hoping you'll do another video on how to implement and get the best out of Turbolinks. Few resources out there and you did a good job with the marketing :D

I definitely will. I also need to learn some around Swift and Android so that I can make some example apps using the Turbolinks adapters. That might mean we'll have a GoRails mobile app at some point. :)

Itzik Ben Hutta ·

Why not React Native? It will save you a lot of time. Or you can wait a year or so. Google plans to ditch Java in favor of Swift for Android development.

Mostly because I'd rather spend most of my time doing the heavy lifting in Rails rather than JS. If you built your Rails frontend in React already, React native is the way to go. Since I'm using Turbolinks already and because I don't have any complex JS widgets on the frontend to need React, the Turbolinks adapters are the best solution for me. React could just as easily fill the same gaps, just fits well for me.

Itzik Ben Hutta ·

We are talking about a mobile app right? How can Rails do the heavy lifting? It will just serve as the API no? So instead of consuming that with two different platforms just use JavaScript for all. Basecamp uses Turbolinks, but there mobile app is also hybrid as far as I know.

With Turbolinks on mobile, you get a web view that embeds the Rails site just like you would have in your browser, but you can override link clicks with native code. So all the stuff you see on mobile is just as if you were viewing it in the browser. It's a hybrid app because of the webview, but easily intercepts those things to do native Swift or whatever. Turbolinks would only need the server to return HTML and so you don't really need to build an API.

React Native is somewhat similar in that you're still sharing the same app code with the main website, but you will have to build an API to make React work, and you'll need to do some extra work to serve up the HTML as well.

Itzik Ben Hutta ·

I didn't know it's possible to have a mobile app without building an API. That's good to know.

Give their readme a look on the new iOS adapter. It might help wrap your head around it a bit.

Basically your mobile app just ends up primarily being a WebView (webkit browser full screen) and it let's you set the website. This is similar to things like PhoneGap in the past, except that the code is all just your public website meaning you can update your mobile app at any time by deploying your website again. Pretty slick! I'm not sure if React Native lets you do things like that.
Here is a video explaining how the guys/girls at basecamp build(the basics of course) their iOS app using turbolinks 5

Another suggestion is a non-rails issue, but fundamental nonetheless: focus on the database queries themselves. A great suggestion I have held dear over the years is to ask "what are the critical queries an application may have?" (the most frequent one, the most valuable, the most calculation intense...) On that basis, with a knowledge of how databases index, one can often find a data structure that is more efficient than another (conception over optimisation). Large test data sets for different data structures allow to validate design choices. To me, that is the core of the onion...

Chris, any chance you could go into detail about how to set up nginx and passenger to properly utilize the resources of your server? I follow your guides when installing so no fine tuning is ever done to my servers. Also would love to see how to set up redis for caching.

Anthony Lee ·

Thanks Chris. I would love to see how you make improvements on all the external API calls for getting data from different services.

Does your 2GB droplet contain your entire stack (db/cache/nginx/passenger) or did you break out the db/cache?

It also contains the DB and cache because neither are that large. I still have 400MB of RAM free right now.

I would love to watch a serie , instead of a bunch of randoms episodes, something like laracasts but for rails..... A lot of people will pay for that

I've been realizing I need to make that transition soon anyways just because there are way too many screencasts to keep track of at this point. :)

I'll probably be migrating to a bunch of small series over the next few weeks!

thanks mate!

Jordano Moscoso ·

Question, maybe to clarify some things, if you can, please answer, thanks.
Why did you choose digitalocean over heroku?
PD: Im thinking about changing to digitalocean because in heroku every add-on in production mode is paid, and if you have few your are going to paid 3x times more than having a digitalocean($20). But i not sure if i'll make the right things in digitalocean.

I chose DO because I like running my own servers and its significantly cheaper than running on Heroku for personal or small business projects. You'll have to do a lot more work, but it can be fun so long as you make sure you have backups and all that in place.

I’m watching this for the first time now (in 2021) and it’s awesome to see how spot on Chris is with his use and recommendation of Turbolinks.

Very helpfull as always, thanks Chris!

Quick question:

  • What would happen in the hypothetical "exaggerated" case of upgrading the Digital Ocean plan to, say, 256GB of memory. All other things being equal, would this fix the loading speed and overall site performance without the need to optimize the frontend, assets or cache?

More RAM would help you run more Rails processes at once so you could serve more users at once, but each individual request will still need to be optimized to run as quick as possible. Caching & optimizing assets is still important and a bigger CPU can help process requests slightly faster.

Awesome Chris, thanks for your response!

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 69,840+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.