dwmkerr / sharpgl

Use OpenGL in .NET applications. SharpGL wraps all modern OpenGL features and offers a powerful scene graph to aid development.
MIT License
749 stars 300 forks source link

Improve speed of looking up OpenGL extension functions #215

Closed ftlPhysicsGuy closed 1 year ago

ftlPhysicsGuy commented 1 year ago

The OpenGLExtensions.cs file in this commit (you can ignore the whitespace changes in OpenGL.cs) provides a faster method for finding a given OpenGL extension function. Rather than creating the delegate for a given type name and putting it in a dictionary for lookup, this new code introduces a static, generic class that can be generated at runtime for any needed delegate type and provides the delegate as a property of the class (generated the first time it is called). In this way, we're letting the application auto-generate or retrieve (if previously generated) the static instance of the class to provide the delegate instead of using a slower dictionary lookup. Testing with 15 items in the dictionary shows about 7 times better performance. While the action is incredibly fast either way, I figure faster should be better (and perhaps more elegant -- though that's matter of taste).

This is one of several modifications I make to the SharpGL source code any time I download the latest version for use in my projects. I intent to put out individual pull requests for each of them, hoping to improve the project for all. Thank you for your consideration.

codecov[bot] commented 1 year ago

Codecov Report

Merging #215 (ef50555) into master (a37721c) will not change coverage. The diff coverage is n/a.

@@          Coverage Diff           @@
##           master    #215   +/-   ##
======================================
  Coverage    3.16%   3.16%           
======================================
  Files          90      90           
  Lines        3697    3697           
  Branches      657     657           
======================================
  Hits          117     117           
  Misses       3575    3575           
  Partials        5       5           

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

dwmkerr commented 1 year ago

Amazing - 15 times faster sounds fantastic thanks @ftlPhysicsGuy !