DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 968,873 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Skip turbo broadcasting to speed up seeding process in Rails
Edwin Mak
Edwin Mak

Posted on

Skip turbo broadcasting to speed up seeding process in Rails

Introduction

We discovered that our seeding process for our rails application was getting very slow by turbo broadcasting via callbacks triggered by saving models. Although this works as intended, we certainly don't need to broadcast turbo frames in the seeding process and just serves to slow down the seeding process without any benefits.

Solution

We were able to speed up the seeding process by 3x (~140s to ~40s) by disabling turbo broadcasting in seeding. You can disable them too by inserting this code snippet before your seeding process:

class Turbo::StreamsChannel
  [:broadcast_append_to, :broadcast_prepend_to, :broadcast_replace_to, :broadcast_remove_to].each do |method|
    define_singleton_method(method) do |*args|
      return nil
    end
  end
end

# SEEDING PROCESS BEGINS
Enter fullscreen mode Exit fullscreen mode

Conclusion

We were able to improve the developer experience by making the
seeding process quicker with a short snippet of code. Shaving off about a minute of seeding seems insignificant, but it adds up!

Hope this helps!

Top comments (0)

๐ŸŒš Friends don't let friends browse without dark mode.

Sorry, it's true.