Skip to content

Patch for python builtin enum module to achieve best performance

Notifications You must be signed in to change notification settings

Bobronium/fastenum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastenum

Patch for builtin enum module to achieve best performance

TL;DR

  • up to 6x faster members access
  • up to 10x faster members name/value access
  • up to 2x faster values positive check
  • up to 3x faster values negative check
  • up to 3x faster iteration

To enable patch, just import fastenum once:

Make sure you import it before importing anything else, otherwise things could (will) break
import fastenum
assert fastenum.enabled

from enum import Enum
assert Enum.__is_fast__()

What's changed?

  • EnumMeta.__getattr__ is removed
  • DynamicClassAttribute is removed in favor of instance attributes
  • name/value are ordinal attributes and put in __slots__ when possible
  • _missing_ type check is removed, as it was re-e-e-ally slowing things down (kinda breaking change, but who cares?)
  • _order_ was removed as since python 3.6 dicts preserve order
  • some other minor improvements

I feel that this actually needs to be in stdlib, but patching all this stuff was actually easier for me that opening issue in python bug tracker

About

Patch for python builtin enum module to achieve best performance

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published