Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8665041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:23:18+00:00 2026-06-12T17:23:18+00:00

Why is the PropertyInfo methods for getting and setting a property so slow? If

  • 0

Why is the PropertyInfo methods for getting and setting a property so slow? If I build a delegate using Reflection.Emit, it is much faster.

Are they doing something important, so that the time they take can be justified? That is… am I missing something by using Reflection.Emit to build delegates instead of usign the GetValue and SetValue of the PropertyInfo (aside of development speed)?

PS: Please, give evidence, not only guessing!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:23:19+00:00Added an answer on June 12, 2026 at 5:23 pm

    The implementation of RuntimePropertyInfo (which is the concrete subclass of PropertyInfo for runtime types) implements GetValue and SetValue by invoking the getter and setter methods via reflection (MethodInfo.Invoke), whereas your generated delegate probably calls the methods directly. Therefore, the question boils down to: why is RuntimeMethodInfo.Invoke so slow when compared to a compiled invocation?

    When you decompile (or look at the reference sources for) RuntimeMethodInfo.Invoke, you can see that this is probably because Invoke carries out a lot of tasks:

    • it performs consistency checks (do the number and types of parameters passed match the signature? does the instance passed match the declaring type? was an instance passed although the method is static?),
    • it performs visibility and (if visibility checks are circumvented) security checks,
    • it unwraps the parameters array, treating ref parameters in a special way so that they can be written back to later,
    • it unboxes parameters if necessary,
    • it needs to find the method pointer based on the runtime type handle and method handle associated with the RuntimeMethodHandle and then invoke the method,
    • it boxes the return value if necessary, and
    • it boxes and puts into the parameter array any ref/out parameters.

    The runtime will perform similar consistency, security, and visibility checks when it compiles your delegate into executable native code. It also emits code for boxing/unboxing, etc. However, it only needs to do these things once, and can then guarantee that the code is safe to execute. This makes the actual method call a very cheap operation (load the parameters and jump to the method address).

    In contrast, every call to RuntimeMethodInfo.Invoke (and thus to GetValue/SetValue) needs to repeat all the work, since the context – parameters, instance, and usage of the return type – is not known. And this is probably why it is so slow.

    About what you might be missing: if you emit your own property invocation delegates, you of course need to deal with boxing/unboxing, ref/out parameters, etc. yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Reflection to set a property value via PropertyInfo.SetValue(); The property in question
Im trying to change a property value (using reflection) that matches with the column
I need a function with the following signature: System.Reflection.PropertyInfo getPropertyInfo(System.Type type, string NavigationPath) or
I am working on a method that compares two objects using reflection. The object
Is there a simple way to get the PropertyInfo for a property in a
I am getting this error on a routine which uses reflection to dump some
How to convert PropertyInfo to property expression which can be used to invoke StructuralTypeConfiguration<TStructuralType>.Ignore<TProperty>(Expression<Func<TStructuralType,
Same for methods too: I am given two instances of PropertyInfo or methods which
I want to add an item to a Generic list using reflection. In the
I've been trying to execute generic methods and using recursion. The problem is that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.