Skip to content

Avoid reflection in IStructuralReadWrite.Read #2669

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

Open
joshua-spacetime opened this issue Apr 24, 2025 · 6 comments · May be fixed by #2725
Open

Avoid reflection in IStructuralReadWrite.Read #2669

joshua-spacetime opened this issue Apr 24, 2025 · 6 comments · May be fixed by #2725
Assignees

Comments

@joshua-spacetime
Copy link
Collaborator

That is, fix this TODO:

// TODO: use `RuntimeHelpers.GetUninitializedObject` as an optimisation here.
// We tried but couldn't do this because BitCraft relies on being able
// to add and initialize custom fields on autogenerated classes.

Currently each row object is instantiated using reflection during deserialization which represents a significant portion of the total cost as the following profile snippet demonstrates.

Image
@kazimuth
Copy link
Contributor

kazimuth commented Apr 25, 2025

I didn't realize new T() compiles to something with reflection, that's nasty. Life without monomorphisation I guess.

@joshua-spacetime
Copy link
Collaborator Author

Note, if the above TODO cannot be resolved, an alternative would be to cache new T() and just copy it for each row decode.

@joshua-spacetime joshua-spacetime self-assigned this Apr 29, 2025
@joshua-spacetime
Copy link
Collaborator Author

Fixed potentially by #2677

@joshua-spacetime
Copy link
Collaborator Author

Blocked waiting on bot test

@joshua-spacetime
Copy link
Collaborator Author

Bot test of #2677 showed no improvements.

@joshua-spacetime joshua-spacetime changed the title Use GetUninitializedObject in IStructuralReadWrite.Read Avoid reflection in IStructuralReadWrite.Read May 9, 2025
@joshua-spacetime joshua-spacetime linked a pull request May 9, 2025 that will close this issue
2 tasks
@joshua-spacetime
Copy link
Collaborator Author

Using a codegen approach instead #2725

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

Successfully merging a pull request may close this issue.

2 participants