I was programming some visual tooling to see which topics are parents of others and I noticed that IceCommit >> isParentOf: is much too slow. Thankfully there is a good way around this by using the repository above the given commit to call mergeBaseBetween:and: (I believe my use case was using IceLibgitRepository). This sped up the operation from failing to finish to working in 6 seconds.
Here is an example implementation of this technique from one of my classes
Also another note on performance, when running this on 66 topics asking each other if they are the parent this is still not fully optimal, it seems to spend most of the time calling LGitExternalEnumerationUInt32 class>>fromInteger:. If this is from the return value to check the ancestor against, then this can be optimized out. below is the performance trace I had when I ran the naive n^2 algorithm checking parent relations.
I was programming some visual tooling to see which topics are parents of others and I noticed that
IceCommit >> isParentOf:
is much too slow. Thankfully there is a good way around this by using the repository above the given commit to callmergeBaseBetween:and:
(I believe my use case was using IceLibgitRepository). This sped up the operation from failing to finish to working in 6 seconds.Here is an example implementation of this technique from one of my classes
https://github.com/mariari/Misc-GT-Scripts/blob/master/src/MiscGTScripts/GitTopicInfo.class.st#L79
Here
topic
returns aIceGitRemoteBranch
, but anyIceCommitish
subclass should work for this implementation.Basically we just compare the commit id of ourselves and check if that is the merge base. If it is, then great we are the parent!
There are better ways to do this, the merge base itself offers a
--is-ancestor
flag which would likely be even more efficient.https://git-scm.com/docs/git-merge-base
Also another note on performance, when running this on 66 topics asking each other if they are the parent this is still not fully optimal, it seems to spend most of the time calling
LGitExternalEnumerationUInt32 class>>fromInteger:
. If this is from the return value to check the ancestor against, then this can be optimized out. below is the performance trace I had when I ran the naive n^2 algorithm checking parent relations.https://pomf2.lain.la/f/z5fwopij.png