Skip to content

Stop unneccessary copies of class_hierarchyt #2971

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

Conversation

JohnDumbell
Copy link
Contributor

If the symbol table is large enough all the copies cause a significant slowdown to the transformation of Java -> GOTO.

This just adds references to a few places where it seems they were missed.

@@ -68,7 +68,7 @@ resolve_inherited_componentt::inherited_componentt
}

const class_hierarchyt::idst &parents=
class_hierarchy.class_map[current_class].parents;
class_hierarchy.class_map.at(current_class).parents;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a precondition that checks that it is there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I never had an exception thrown, in the spirit of keeping the code functionally the same it might be better to do a find on the map, then only do anything more if that succeeds.

Think that would be prudent, or leave it as-is and add the precondition?

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 2fbad7e).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85047439

Copy link
Contributor

@mgudemann mgudemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@kroening kroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use the naming convention 'owned'/'borrowed', and I'd be reluctant to introduce it here as a special case.

What we do to prevent copying of potentially large data structures is to delete the copy constructor and assignment operator; I'd do the same for the class hierarchy.

@smowton
Copy link
Contributor

smowton commented Sep 18, 2018

@kroening if not owned/borrowed what naming do you prefer?

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR comment says:

If the symbol table is large enough all the copies cause a significant slowdown to the transformation of Java -> GOTO.

This just adds references to a few places where it seems they were missed.

This info is missing from the commit message, but also neither has actual data points (what is "significant" - 5 seconds, 10 minutes, 2 days; what's the impact of adding references?).

@@ -70,7 +70,8 @@ class resolve_inherited_componentt
const irep_idt &component_name,
const irep_idt &user_class_name);

class_hierarchyt class_hierarchy;
const class_hierarchyt &class_hierarchy;
class_hierarchyt owned_class_hierarchy;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There already has been a discussion about terminology, which we may be able to steer to some conclusion if someone could explain what the difference between those two actually is? Why can't they be the same?

Copy link
Contributor Author

@JohnDumbell JohnDumbell Sep 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was purely to get around the fact that reference fields require some value on construction and that class_hierarchyt gets populated by a () operator, so needs something to exist before passing a symbol table too it.

Edit: actually don't think my suggestion would work, so any others would be appreciated.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is the constructor that take a single argument (just the symbol table) actually ever called!? Maybe the simple fix is to get rid of that constructor?

Copy link
Contributor Author

@JohnDumbell JohnDumbell Sep 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLion doesn't think so, but is this something other people can/would be using? Otherwise I'm good with removing it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are any such users, then they just need to create the class hierarchy themselves and pass it as second argument.

Unless someone steps up immediately, I'd just go with removing it. Commits can always be reverted, this isn't a one-way door.

@JohnDumbell JohnDumbell force-pushed the jd/bugfix/unnecessary_class_hierarchy_copy branch from 2fbad7e to 65b81c5 Compare September 19, 2018 13:13
@JohnDumbell
Copy link
Contributor Author

JohnDumbell commented Sep 19, 2018

I've updated with all the comments given so far. I've also removed the constructor from resolve_inherited_componentt as we're not using it, which solves the issue about duplicated fields and naming convention.

In regards to actual data around improvements: I was running with a symbol table of around 220,000, and with this change it went from hours to 2-3 minutes to parse and then attempt to generate GOTO. I can't provide exactly how long the pre-change took to get to the same point because after it took around an hour I just set about looking to see if there were any easy ways to speed it up. I can give exacts if required, but it'll probably take a day to get.

There should be no logical impacts around it becoming a reference vs a copy, the code using it only did look-ups from what I could see.

In cases where the symbol table was large (220,000) continuous copies of class_hierarcht across a few method/object boundaries were causing noticable slowdown. This just adds in a few references where they seem to have been accidentally missed.
@JohnDumbell JohnDumbell force-pushed the jd/bugfix/unnecessary_class_hierarchy_copy branch from 65b81c5 to 00550cd Compare September 19, 2018 13:42
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR failed Diffblue compatibility checks (cbmc commit: 65b81c5).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85296801
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

@thk123
Copy link
Contributor

thk123 commented Sep 19, 2018

Above failure looks like you've recently rebase - hopefully Joelbot will post some positive news shortly (given this is an interface change, could you wait until you do get a positive response).

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 00550cd).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85301103

@kroening
Copy link
Member

@JohnDumbell Please remember that performance story for future company training sessions!

@kroening kroening removed their assignment Sep 19, 2018
@kroening kroening merged commit 032f33b into diffblue:develop Sep 19, 2018
@JohnDumbell JohnDumbell deleted the jd/bugfix/unnecessary_class_hierarchy_copy branch October 23, 2018 16:01
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.

8 participants