Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ReferenceIntersector.FindNearest much slower in Revit 2021

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
mehdi.blanchard
1420 Views, 12 Replies

ReferenceIntersector.FindNearest much slower in Revit 2021

mehdi.blanchard
Enthusiast
Enthusiast
 

To do a slope analysis on a site I project a grid of point on a Topography. For some reason this is much slower in Revit 2021 than it is in Revit 2020.

surface.png

The reference intersector is created as follows:

ReferenceIntersector refIntersector = new ReferenceIntersector(topo.Id, FindReferenceTarget.Mesh, view);

 

Then I do a loop over all my points and use a System.Diagnostics.Stopwatch to measure the total time taken everytime I call the FindNearest function, to make sure I measure only the FindNearest call:

 

StartWatch();
ReferenceWithContext referenceWithContext = refIntersector.FindNearest(pt, rayDirection);
StopWatch();

 

Revit 21: Total Projection Time = 233s (number of projections: 6332)

Revit 20: Total Projection Time = 147s (number of projections: 6332)

 

This is almost two times slower !!

 

Is anybody experiencing this as well?

 

The topography is 2.1km x 1.3km long

0 Likes

ReferenceIntersector.FindNearest much slower in Revit 2021

 

To do a slope analysis on a site I project a grid of point on a Topography. For some reason this is much slower in Revit 2021 than it is in Revit 2020.

surface.png

The reference intersector is created as follows:

ReferenceIntersector refIntersector = new ReferenceIntersector(topo.Id, FindReferenceTarget.Mesh, view);

 

Then I do a loop over all my points and use a System.Diagnostics.Stopwatch to measure the total time taken everytime I call the FindNearest function, to make sure I measure only the FindNearest call:

 

StartWatch();
ReferenceWithContext referenceWithContext = refIntersector.FindNearest(pt, rayDirection);
StopWatch();

 

Revit 21: Total Projection Time = 233s (number of projections: 6332)

Revit 20: Total Projection Time = 147s (number of projections: 6332)

 

This is almost two times slower !!

 

Is anybody experiencing this as well?

 

The topography is 2.1km x 1.3km long

Labels (1)
12 REPLIES 12
Message 2 of 13

jeremy_tammik
Autodesk
Autodesk

Thank you for the interesting observation.

 

If you would like to share a minimal reproducible case, I will gladly pass it on the the development team for analysis:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

Thank you for the interesting observation.

 

If you would like to share a minimal reproducible case, I will gladly pass it on the the development team for analysis:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 13

mehdi.blanchard
Enthusiast
Enthusiast

Hi Jeremy,

Thanks for looking into this.

 

I can confirm that this is an issue as I can even reproduce it on the rac_advanced_sample_project.rvt

 

The minimal code below can be used to reproduce the issue.

 

Here is the difference on a large site that I have (2.1km x 1.3km):

Revit 2020: Projection Time == 69s (3000)
Revit 2021: Projection Time == 112s (3000)

 

and here is the difference on the rac_advanced_sample_project.rvt

Revit 2020: Projection Time == 17s (30000)
Revit 2021: Projection Time == 29s (30000)

 

To run the test, you just need to duplicate the 3D view, turn off the section Box and in VG remove everything but Topography (not sure it makes a difference, but I was doing it). Then select the Topography and run an external command that calls the function below:

(note: adjust the counter based on the size of the site as shown in the comments)

 

        void PerformanceTest(UIDocument uiDoc, Document doc)
        {
            // Get the selected Topography
            Selection userSel = uiDoc.Selection;
            ICollection<ElementId> set = userSel.GetElementIds();

            TopographySurface topo = null;
            foreach (ElementId id in set)
            {
                Element element = doc.GetElement(id);
                if (element is TopographySurface)
                {
                    topo = (TopographySurface)element;
                    break;
                }
            }

            if (topo == null)
            {
                return;
            }

            View activeView = doc.ActiveView;
            if (!(activeView is View3D))
            {
                return;
            }
            View3D view = activeView as View3D;

            // Get topo center
            BoundingBoxXYZ bound = topo.get_BoundingBox(view);
            XYZ rayBase = new XYZ((bound.Max.X + bound.Min.X) / 2, (bound.Max.Y + bound.Min.Y) / 2, bound.Min.Z - 10);

            // Create the intersector
            List<ElementId> meshId = new List<ElementId>();
            meshId.Add(topo.Id);
            ReferenceIntersector refIntersector = new ReferenceIntersector(topo.Id, FindReferenceTarget.Mesh, view);

            Random rnd = new Random();
            Stopwatch watch = new Stopwatch();
            int i;
            for (i = 0; i < 30000; i++) // on a large site use 3000, on a small site use 30000
            {
                // Create a random point around the topo center
                XYZ pt = new XYZ(rayBase.X + rnd.Next(1, 100) - 50, rayBase.Y + rnd.Next(1, 100) - 50, rayBase.Z);
                watch.Start();
                ReferenceWithContext referenceWithContext = refIntersector.FindNearest(pt, XYZ.BasisZ);
                watch.Stop();
                if (referenceWithContext != null)
                {
                    //
                }
            }
            Debug.Print("Projection Time == " + Math.Round((double)watch.ElapsedMilliseconds / 1000).ToString() + $"s ({i})");
        }

 

Hi Jeremy,

Thanks for looking into this.

 

I can confirm that this is an issue as I can even reproduce it on the rac_advanced_sample_project.rvt

 

The minimal code below can be used to reproduce the issue.

 

Here is the difference on a large site that I have (2.1km x 1.3km):

Revit 2020: Projection Time == 69s (3000)
Revit 2021: Projection Time == 112s (3000)

 

and here is the difference on the rac_advanced_sample_project.rvt

Revit 2020: Projection Time == 17s (30000)
Revit 2021: Projection Time == 29s (30000)

 

To run the test, you just need to duplicate the 3D view, turn off the section Box and in VG remove everything but Topography (not sure it makes a difference, but I was doing it). Then select the Topography and run an external command that calls the function below:

(note: adjust the counter based on the size of the site as shown in the comments)

 

        void PerformanceTest(UIDocument uiDoc, Document doc)
        {
            // Get the selected Topography
            Selection userSel = uiDoc.Selection;
            ICollection<ElementId> set = userSel.GetElementIds();

            TopographySurface topo = null;
            foreach (ElementId id in set)
            {
                Element element = doc.GetElement(id);
                if (element is TopographySurface)
                {
                    topo = (TopographySurface)element;
                    break;
                }
            }

            if (topo == null)
            {
                return;
            }

            View activeView = doc.ActiveView;
            if (!(activeView is View3D))
            {
                return;
            }
            View3D view = activeView as View3D;

            // Get topo center
            BoundingBoxXYZ bound = topo.get_BoundingBox(view);
            XYZ rayBase = new XYZ((bound.Max.X + bound.Min.X) / 2, (bound.Max.Y + bound.Min.Y) / 2, bound.Min.Z - 10);

            // Create the intersector
            List<ElementId> meshId = new List<ElementId>();
            meshId.Add(topo.Id);
            ReferenceIntersector refIntersector = new ReferenceIntersector(topo.Id, FindReferenceTarget.Mesh, view);

            Random rnd = new Random();
            Stopwatch watch = new Stopwatch();
            int i;
            for (i = 0; i < 30000; i++) // on a large site use 3000, on a small site use 30000
            {
                // Create a random point around the topo center
                XYZ pt = new XYZ(rayBase.X + rnd.Next(1, 100) - 50, rayBase.Y + rnd.Next(1, 100) - 50, rayBase.Z);
                watch.Start();
                ReferenceWithContext referenceWithContext = refIntersector.FindNearest(pt, XYZ.BasisZ);
                watch.Stop();
                if (referenceWithContext != null)
                {
                    //
                }
            }
            Debug.Print("Projection Time == " + Math.Round((double)watch.ElapsedMilliseconds / 1000).ToString() + $"s ({i})");
        }

 

Message 4 of 13

RPTHOMAS108
Mentor
Mentor

I would also consider the influence of other add-ins i.e. is this an issue with the API method or something introduced in 2021 (in-built (1st party?) and 3rd party) that goes on in the background slowing down the pace.

 

Would suggest striping out other add-ins for comparison (from all the various locations of loading them) if not already done so. 

0 Likes

I would also consider the influence of other add-ins i.e. is this an issue with the API method or something introduced in 2021 (in-built (1st party?) and 3rd party) that goes on in the background slowing down the pace.

 

Would suggest striping out other add-ins for comparison (from all the various locations of loading them) if not already done so. 

Message 5 of 13

mehdi.blanchard
Enthusiast
Enthusiast

@RPTHOMAS108 I have removed the other add-ins in the AppData folder (can't remove the add-ins in Program Data as I don't have admin rights).

 

I get the exact same time. Revit 21 is much slower. I have created an add-ins to create Solar Farms and it is a shame that I don't get the same performance in Revit 21.

 

Could someone at Autodesk @jeremy_tammik have alook into this? I have provided the code to reproduce the issueLitchfield 5 - Enscape.png

 

 

@RPTHOMAS108 I have removed the other add-ins in the AppData folder (can't remove the add-ins in Program Data as I don't have admin rights).

 

I get the exact same time. Revit 21 is much slower. I have created an add-ins to create Solar Farms and it is a shame that I don't get the same performance in Revit 21.

 

Could someone at Autodesk @jeremy_tammik have alook into this? I have provided the code to reproduce the issueLitchfield 5 - Enscape.png

 

 

Message 6 of 13

jeremy_tammik
Autodesk
Autodesk

I will gladly raise this issue with the development team. Can you please share the appropriately modified sample model here as well, so they do not have to duplicate those steps, and to make absolutely sure that we are talking about the same thing? Thank you!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

I will gladly raise this issue with the development team. Can you please share the appropriately modified sample model here as well, so they do not have to duplicate those steps, and to make absolutely sure that we are talking about the same thing? Thank you!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 7 of 13

mehdi.blanchard
Enthusiast
Enthusiast

Hi @jeremy_tammik ,

 

Please find the file attached. This is the sample file rac_advanced_sample_project.rvt that has been purged.

 

There is a 3D view called "Reference Intersector Test" that can be used to run the script provided. With this file and 30,000 iterations (in the FOR loop) I get:

17s in Revit 2020

27s in Revit 2021

 

Just in case someone asks why would I need 30,000 iterations:

  • the file provided is a very simple site, on a large complex site you'll need a lot less tests (ex: 3000) to see a significant increase of time in Revit 2021
  • I need to do a retopology of the site which means that I need to test a lot of points as shown below (using AVF):east_west.png

Thanks!

0 Likes

Hi @jeremy_tammik ,

 

Please find the file attached. This is the sample file rac_advanced_sample_project.rvt that has been purged.

 

There is a 3D view called "Reference Intersector Test" that can be used to run the script provided. With this file and 30,000 iterations (in the FOR loop) I get:

17s in Revit 2020

27s in Revit 2021

 

Just in case someone asks why would I need 30,000 iterations:

  • the file provided is a very simple site, on a large complex site you'll need a lot less tests (ex: 3000) to see a significant increase of time in Revit 2021
  • I need to do a retopology of the site which means that I need to test a lot of points as shown below (using AVF):east_west.png

Thanks!

Message 8 of 13

jeremy_tammik
Autodesk
Autodesk
Accepted solution

Dear Mehdi,

 

Thank you for your reproducible case.

 

I logged the issue REVIT-174745 [ReferenceIntersector slowdown in Revit 2021] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

Dear Mehdi,

 

Thank you for your reproducible case.

 

I logged the issue REVIT-174745 [ReferenceIntersector slowdown in Revit 2021] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 9 of 13

jeremy_tammik
Autodesk
Autodesk

Dear Mehdi,

 

Thank you for your patience with this. Just a small update to let you know that the development team analysed the issue REVIT-174745 [ReferenceIntersector slowdown in Revit 2021] and reproduced the slowdown you describe. No idea how long it will take to fix, though, and when such a fix might become publicly available...

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

Dear Mehdi,

 

Thank you for your patience with this. Just a small update to let you know that the development team analysed the issue REVIT-174745 [ReferenceIntersector slowdown in Revit 2021] and reproduced the slowdown you describe. No idea how long it will take to fix, though, and when such a fix might become publicly available...

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 10 of 13

mehdi.blanchard
Enthusiast
Enthusiast
Hi Jeremy,
Good to hear that they can reproduce it. Thanks for the update!
Kind Regards,
Mehdi
0 Likes

Hi Jeremy,
Good to hear that they can reproduce it. Thanks for the update!
Kind Regards,
Mehdi
Message 11 of 13

jeremy_tammik
Autodesk
Autodesk

Yup. They reproduced, analysed, performed some minor fixes, and determined that the issue requires further exploration and a possible code fix in a future version. For this, they raised a new ticket REVIT-175514 [ReferenceIntersector slowdown in Revit 2021]. Please make a note of this number for future reference as well.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

Yup. They reproduced, analysed, performed some minor fixes, and determined that the issue requires further exploration and a possible code fix in a future version. For this, they raised a new ticket REVIT-175514 [ReferenceIntersector slowdown in Revit 2021]. Please make a note of this number for future reference as well.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 12 of 13

jeremy_tammik
Autodesk
Autodesk
Accepted solution

Dear Mehdi,

 

Thank you again for your patience with this.

 

After an impressive amount of discussion, research, analysis, and two change requests, the development team resolved the issue. The summary is short and sweet:

 

It turned out that 'FORCEINLINE' does make a significant difference in the way the compiler treats even simple functions.

 

We restored this for XYZ and UV and the macro now runs at the same speed as before.

 

Unfortunately, you may have to wait for the next major release of Revit to actually experience the improvement

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

Dear Mehdi,

 

Thank you again for your patience with this.

 

After an impressive amount of discussion, research, analysis, and two change requests, the development team resolved the issue. The summary is short and sweet:

 

It turned out that 'FORCEINLINE' does make a significant difference in the way the compiler treats even simple functions.

 

We restored this for XYZ and UV and the macro now runs at the same speed as before.

 

Unfortunately, you may have to wait for the next major release of Revit to actually experience the improvement

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 13 of 13

mehdi.blanchard
Enthusiast
Enthusiast

Haha! Funny that it sparked a heated debate!

Thank you very much Jeremy for getting this sorted. 

Will look forward to the next major release.

 

Kind Regards,

Mehdi

0 Likes

Haha! Funny that it sparked a heated debate!

Thank you very much Jeremy for getting this sorted. 

Will look forward to the next major release.

 

Kind Regards,

Mehdi

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report