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

Improve performance of the Julia GC integration #3516

Merged
merged 3 commits into from
Jul 17, 2019

Conversation

rbehrends
Copy link
Contributor

@rbehrends rbehrends commented Jun 21, 2019

This is both a performance fix and an attempt to refactor part of the Julia GC integration.

On the performance side, this avoids rescanning unused task stacks unnecessarily. See this related GAP.jl issue.

I've also attempted a migration of the GC integration to C++. The motivation for that was the need to have clean data types, which were messy to handle in C (especially the generics). This probably requires some testing.

Also, while GAP currently already uses some C++ code, it is not linked against the C++ stdlib, which means that things such as new and delete won't properly work. Therefore, the C++ is written to work without any such features and is primarily used for abstraction. Care was also taken to only require C++98 features (build with CXXFLAGS="-g -O2 -std=c++98" to verify).

There's currently a short test, build with CXXFLAGS=-DTEST_JULIA_GC_INTERNALS to run it instead of GAP. This is only temporary and meant to be removed before this PR is being merged.

Note that the C++ stdlib issues could be resolved by using CXX instead of CC for the LINK command in Makefile.rules, but I am not sure if that is desirable.

@rbehrends rbehrends added do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) topic: performance bugs or enhancements related to performance (improvements or regressions) topic: kernel kind: discussion discussions, questions, requests for comments, and so on topic: julia Julia GC integration and related matters labels Jun 21, 2019
@codecov
Copy link

codecov bot commented Jun 23, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@2e9ace1). Click here to learn what that means.
The diff coverage is 42.78%.

@@            Coverage Diff            @@
##             master    #3516   +/-   ##
=========================================
  Coverage          ?   84.48%           
=========================================
  Files             ?      698           
  Lines             ?   345258           
  Branches          ?        0           
=========================================
  Hits              ?   291695           
  Misses            ?    53563           
  Partials          ?        0
Impacted Files Coverage Δ
src/dynarray.h 14.54% <14.54%> (ø)
src/baltree.h 40.78% <40.78%> (ø)
src/julia_gc.c 82.44% <69.84%> (ø)

@coveralls
Copy link

coveralls commented Jun 23, 2019

Coverage Status

Coverage decreased (-0.02%) to 84.3% when pulling 7431c7c on rbehrends:julia-gc-perf-quickfix into 2e9ace1 on gap-system:master.

src/julia_gc.cc Outdated
if (!FullGC) {
// This is a temp hack to work around a problem with the
// generational GC. Basically, task stacks are being scanned
// regardless of whether they are old or new. In order to avoid
Copy link
Member

Choose a reason for hiding this comment

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

Is this a bug in Julia, resp. something there we don't understand? If so, can you please provide a link to the relevant Julia issue report, resp. the relevant discussion on the Julia discourse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if its a bug or an inefficiency. Basically, as I understand it, the task stacks can be roots themselves without being referenced from elsewhere. So, in parts, this is most likely intentional and simply hasn't created any performance issues, as task stacks tend to be short.

@rbehrends rbehrends force-pushed the julia-gc-perf-quickfix branch 2 times, most recently from 47324a9 to 3688ac0 Compare June 27, 2019 17:39
@fingolfin
Copy link
Member

@rbehrends this version doesn't compile cleanly, at least on Travis.

@rbehrends
Copy link
Contributor Author

@fingolfin Yeah, I saw it, for some reason clang incorrectly accepted a static const array size (a C++ leftover), but gcc complained (appropriately so).

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

In principle I am fine with this now.

#define FN(sym) JOIN(Array, sym)

#define JOIN(s1, s2) JOIN2(s1, s2)
#define JOIN2(s1, s2) s1##s2
Copy link
Member

Choose a reason for hiding this comment

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

These two macros also appear in sortbase.h. And in debug.h, we have them under a different name:

#define _intern_CONCAT_(X, Y)  X ## Y
#define _intern_CONCAT(X, Y)  _intern_CONCAT_(X,Y)

Perhaps we should just give in and move this to, say, src/gaputils.h and document it properly (this is not a change request for this PR, just a general thought. @ChrisJefferson ?)

@rbehrends rbehrends changed the title WIP: Performance fix for the Julia GC integration. Performance fix for the Julia GC integration. Jul 15, 2019
@rbehrends
Copy link
Contributor Author

I've factored out the tests and made testkernel a separate Makefile target under the assumption that more could be added to it later and kept conceptually different from libgap tests, even though the same framework is used. Is that reasonable or should I put them in with the libgap tests?

@fingolfin fingolfin force-pushed the julia-gc-perf-quickfix branch from 4cc0bac to a31119c Compare July 17, 2019 10:46
This introduces a new make target, testkernel.
@fingolfin fingolfin force-pushed the julia-gc-perf-quickfix branch from a31119c to 7431c7c Compare July 17, 2019 12:56
@fingolfin fingolfin merged commit f33b341 into gap-system:master Jul 17, 2019
@fingolfin fingolfin added release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes and removed do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) labels Aug 21, 2019
@fingolfin fingolfin changed the title Performance fix for the Julia GC integration. Fix performance issues in the Julia GC integration Aug 21, 2019
@fingolfin fingolfin added release notes: added PRs introducing changes that have since been mentioned in the release notes and removed release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels Aug 22, 2019
@fingolfin fingolfin changed the title Fix performance issues in the Julia GC integration Improve performance of the Julia GC integration Aug 22, 2019
@olexandr-konovalov olexandr-konovalov added this to the GAP 4.11.0 milestone Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: discussion discussions, questions, requests for comments, and so on release notes: added PRs introducing changes that have since been mentioned in the release notes topic: julia Julia GC integration and related matters topic: kernel topic: performance bugs or enhancements related to performance (improvements or regressions)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants