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

Skip excess cloning of JSONized object_changes #1189

Conversation

stokarenko
Copy link
Contributor

@stokarenko stokarenko commented Mar 13, 2019

Every clone-like operation over the object_changes column will allocate the O(n) of RAM, where n is a kind of complexity of object model in general and applied changes in particular.

Lets skip excess object_changes.to_hash call when the object_changes is a kind of json column.

  • Wrote good commit messages.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new
    code introduces user-observable changes.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.

@stokarenko stokarenko force-pushed the skip_cloning_of_jsonized_object_changes branch from ec58654 to 8d3963e Compare March 13, 2019 07:48
@stokarenko stokarenko mentioned this pull request Mar 13, 2019
6 tasks
@jaredbeck
Copy link
Member

Somehow, this makes more sense to me when I see it as a separate PR. Looks good, I'm just going to add some comments.

@jaredbeck
Copy link
Member

Hmm this may be a breaking change, I'm not sure.

Until now, we have passed a plain Hash to object_changes_adapter.diff. This PR would change that part of our public API, passing a HashWithIndifferentAccess instead.

However, I think this change would not affect the reference implementation of object_changes_adapter.

What do you think? Should we treat this as a breaking change?

@jaredbeck
Copy link
Member

I've added some comments, and fixed the object_changes_adapter API. Please review.

@stokarenko
Copy link
Contributor Author

I feel that change from HashWithIndifferentAccess to pure Hash can be a breaking one, but not vice versa..

On the other hand I'm able to think up some dummy object_changes_adapter implementation which will be sensitive to PR.

Looks like it's better to mark the change as rarely breaking, to be honest with consumers..

@jaredbeck
Copy link
Member

jaredbeck commented Mar 13, 2019

Looks like it's better to mark the change as rarely breaking, to be honest with consumers..

Please see 309a8c1, in which I preserve the public API by using .to_hash.

-         changes = PaperTrail.config.object_changes_adapter.diff(changes)
+         changes = PaperTrail.config.object_changes_adapter.diff(changes.to_hash)

What do you think?

@stokarenko
Copy link
Contributor Author

I've added some comments, and fixed the object_changes_adapter API. Please review.

LGTM! Now there is no any chance to break the things for consumers :)

@jaredbeck jaredbeck merged commit ca4f532 into paper-trail-gem:master Mar 13, 2019
aried3r pushed a commit to aried3r/paper_trail that referenced this pull request Dec 14, 2020
* Skip excess cloning of JSONized `object_changes`

* Suggestions for PR 1189, to be squashed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants