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

Add custom attribute to mark method as expensive #1030

Closed
citizenmatt opened this issue Feb 8, 2019 · 5 comments
Closed

Add custom attribute to mark method as expensive #1030

citizenmatt opened this issue Feb 8, 2019 · 5 comments
Assignees
Milestone

Comments

@citizenmatt
Copy link
Member

Add a new JetBrains.Annotations attribute to mark a method as expensive. Any usage of this method inside a performance critical context would be highlighted as usage of an expensive method, in the same was as GetComponent, Find, etc. are currently handled.

This would be useful for third party assemblies that indirectly call the known Unity APIs that are expensive (e.g. Camera.main calls FindObjectWithTag internally) and could be included as external annotations, or compiled directly into the code. We should add features to make it easy to create or add a reference/package to use the attribute.

Another option is to ship a public attribute in the plugin, or as a package. We can mark it as [Conditional] to prevent a binary dependency, or maybe [Conditional("UNITY_EDITOR")] so the dependency is only there for the editor, which would help if the project was being distributed on the Asset Store or as a package.

We should also think carefully about choosing a name - expensive might not be expressive enough. Maybe something like "performance sensitive"? And it would be worth co-ordinating with R# team to see if it could be shared, or just something with a Unity specific name.

@citizenmatt
Copy link
Member Author

See also RIDER-22807

@JeromeJ
Copy link

JeromeJ commented Jun 10, 2020

I second this. I have an external dll that does implement some kind of frequently called Update method which I'd love being able to tag as "expensive" without having to resort to a hack: Putting a fake call to it in an Unity Update method to trick it seems the wrong way to achieve this.

@Domonion
Copy link

Domonion commented Oct 20, 2020

Implemented, from now you can add // ReSharper restore Unity.ExpensiveCode above your IFunctionDeclaration and you would get this function marked as expensive. Will be available next EAP. @JeromeJ can you please provide an example of the code you would like to mark as expensive? Does this feature solve your problem? If not - please provide it as a separate issue, please! Thank you!

@Domonion Domonion assigned Domonion and unassigned krasnotsvetov Oct 20, 2020
@Domonion
Copy link

Here is an example of avaiable features:
java_TyLQx58N8w

And of course, they do affect the analysis transitively.

@Domonion Domonion added this to the Rider 2020.3 milestone Oct 20, 2020
@limdingwen
Copy link

limdingwen commented Feb 5, 2022

image

Hi, this does not seem to work for me. JetBrains Rider 2021.3.2

Edit: Ignore me I'm dumb. I was looking for // Resharper restore Unity.PerformanceCriticalContext instead.

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

No branches or pull requests

5 participants