On 17 July 2017 at 08:43, Antoine Pitrou <solip...@pitrou.net> wrote:
> > Hello, > > Cost of creating a namedtuple has been identified as a contributor to > Python startup time. Not only Python core and the stdlib, but any > third-party library creating namedtuple classes (there are many of > them). An issue was created for this: > https://bugs.python.org/issue28638 > > Raymond decided to close the issue because: > > 1) the proposed resolution makes the "_source" attribute empty (or, at > least, something else than it currently is). Raymond claims the > "_source" attribute is an essential feature of namedtuples. > I think I understand well enough to say something intelligent… While actual references to _source are likely rare (certainly I’ve never used it), my understanding is that the way namedtuple works is to construct _source, and then exec it to create the class. Once that is done, there is no significant saving to be had by throwing away the constructed _source value. When namedtuple was being considered for inclusion, I actually went so far as to write a proof-of-concept version that worked by creating a class, creating attributes on it, etc. I don’t remember how far I got but the exec version is the version included in the stdlib. I come from a non-Pythonic background so use of exec still feels a bit weird to me but I absolutely love namedtuple and use it constantly. I don't know whether a polished and completed version of my idea could be faster than using exec, but I wouldn't expect a major saving — a whole bunch of code has to run either way.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com