[issue38895] performance degradation creating a mock object (by factor 7-8)
Marcel Zięba added the comment: I've also tested it and can confirm it. Master branch: raw times: 8.43 sec, 7.26 sec, 8.16 sec, 8.4 sec, 7.31 sec 10 loops, best of 5: 72.6 usec per loop v3.8.0: raw times: 13.6 sec, 11.9 sec, 11.6 sec, 11.7 sec, 12.3 sec 10 loops, best of 5: 116 usec per loop v3.7.4: raw times: 2.55 sec, 1.9 sec, 2.7 sec, 2.42 sec, 2.17 sec 10 loops, best of 5: 19 usec per loop -- nosy: +marseel versions: +Python 3.9 ___ Python tracker <https://bugs.python.org/issue38895> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38895] performance degradation creating a mock object (by factor 7-8)
Marcel Zięba added the comment: This is the first commit I've observed slow down: 77b3b7701a34ecf6316469e05b79bb91de2addfa Especially this part looks suspicious https://github.com/python/cpython/commit/77b3b7701a34ecf6316469e05b79bb91de2addfa#diff-ff75b1b83c21770847ade91fa5bb2525R366 -- ___ Python tracker <https://bugs.python.org/issue38895> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38895] performance degradation creating a mock object (by factor 7-8)
Marcel Zięba added the comment: "It seems creating the signature of NonCallableMock.__init__ per mock creation is expensive and since it doesn't change can we just create the signature once and set it as a module level attribute? There might still be room for some more optimisations here to reduce the impact." This is already done in master branch ;) "This could be moved to _get_child_mock so that the Mock creation itself for all other mocks and common use case is faster. Creating child mocks will have the iscoroutine function check performed where maybe we can populate the _spec_async list and use it for subsequent calls." This seems like a reasonable solution. I've tested it and it improves mock creation speed 2x. Do you mind if I create PR for it? I would like to start contributing to CPython ;) -- ___ Python tracker <https://bugs.python.org/issue38895> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com