Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issue when decorator files are loaded multiple times #28

Open
patcoll opened this issue Jun 6, 2017 · 4 comments
Open

Performance issue when decorator files are loaded multiple times #28

patcoll opened this issue Jun 6, 2017 · 4 comments

Comments

@patcoll
Copy link

patcoll commented Jun 6, 2017

Complete Description of Issue

When files containing classes that inherit from Roar::Decorator and use the include Roar::JSON::JSONAPI.resource declaration are dynamically reloaded, there is a performance degradation. As the number of reloads goes up, the performance degradation seems to increase as well.

Steps to reproduce

Simulate dynamic reloading by running the Kernel::load method multiple with the same file. Again, that file should contain a class that inherits from Roar::Decorator and uses the include Roar::JSON::JSONAPI.resource declaration, like so:

class DocumentSingleResourceObjectDecorator < Roar::Decorator
  include Roar::JSON::JSONAPI.resource :articles

  attributes do
    property :title
  end
end

(In our case, we use trailblazer and roar-jsonapi within Rails, and the performance slowdown initially showed up in our development environment. We were able to reproduce the problem without Rails being involved, both in this repo and with a minimal benchmark test case in #29.)

Expected behavior

The time to reload the file with the class in it should exhibit constant-time performance characteristics.

Translation: It should just load quickly and move on.

Actual behavior

Every time the same file is reloaded, there appears to be a significant performance degradation.

Translation: It slows down significantly while loading, causing further use of the class to be delayed.

System configuration

Roar version: 1.1.0

Roar-JSONAPI version: 0.0.3

@myabc
Copy link
Collaborator

myabc commented Jun 6, 2017

@patcoll Have you considered using the lower-level Roar::JSON::JSONAPI::Mixin module?

class DocumentSingleResourceObjectDecorator < Roar::Decorator
  include Roar::JSON::JSONAPI::Mixin
  type :articles

  property :id

  attributes do
    property :title
  end
end

FWIW I'm not completely happy with the API design as it stands. I'd be open to an alternative to using a dynamic module for configuration.

@dmuneras
Copy link

dmuneras commented Jun 7, 2017

@myabc thanks for pointed out to Roar::JSON::JSONAPI::Mixin we will take a look.

@apotonick
Copy link
Member

Hi @dmuneras I already investigated, thanks to you and @patcoll for the excellent benchmark test. The Mixin won't help, I think I know where the problem is. I'll work on it in a few hrs, at a client gig right now 😉

@dmuneras
Copy link

dmuneras commented Jun 7, 2017

Thanks a lot @apotonick and @myabc, looking forward to see what was causing the problem and the real fix. Have a great day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants