DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Data Engineering
  3. Data
  4. High Performance Field Clobbering

High Performance Field Clobbering

Ayende Rahien provides his insight on performance in a scenario for class re-use.

Oren Eini user avatar by
Oren Eini
·
Nov. 07, 16 · Tutorial
Like (3)
Save
Tweet
Share
2.59K Views

Join the DZone community and get the full member experience.

Join For Free

so we are using a particular library in a not so standard way. and in order to gain 10x performance benefit we have to reuse a particular class from this library. this class isn’t meant to be reused, but looking at its code, it is clear that it is perfectly possible to do so. all we need is to set the _started field to false and it will be possible to reuse this instance.

so far, so good. except that the field is private. now, we can’t just implement our own copy of this, because this is a field in the base class that we are extending to plug our extension to the system. we could try submitting a patch for this, but this is a popular library, and tying ourselves to a particular version would suck. this code has also hasn’t changed since at jan 2012, so that is pretty stable. and yes, we are aware of the risk in doing this, unsupported, etc.

now that we decided to do it, the question is how. i created the following epic class:

image title

and here is the simplest option to handle it:

image title

and that gives us:

image title

can we do better?

what happens if we cache the field lookup?

image title

this has significant improvement, right?

image title

but that is still quite high for me. can we do better still?

let us try some dynamic code generation. in this case, we can’t use the much easier expression class to do it, and have to go with direct il generation, which gives:

image title

and the benchmark result?

image title

that is pretty awesome. for comparison purposes, i also did a static delegate and direct set, to compare the costs.

image title

and those give me:

image title

but i think that 2.5 ns is fast enough for me here.

Library Cache (computing) Comparison (grammar) Tying (commerce) Clear (Unix) Patch (computing) Awesome (window manager)

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • DZone's Article Submission Guidelines
  • 11 Observability Tools You Should Know
  • Spring Boot vs Eclipse Micro Profile: Resident Set Size (RSS) and Time to First Request (TFR) Comparative
  • The 5 Books You Absolutely Must Read as an Engineering Manager

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: