Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove python 2 support from ckbytelist constructor #122

Closed
wants to merge 1 commit into from

Conversation

fuzzykat
Copy link
Contributor

@fuzzykat fuzzykat commented Aug 19, 2024

The problem: ckbytelist constructor checks python version for every byte in a loop:

for x in data:
    if sys.version_info[0] <= 2:
        # Python 2
        v = ord(x)
    else:
        # Python 3 and more
        v = x
    self.append(v)

which is redundant and not good for performance. I suppose, just checking python version once during module import would suffice. This PR removes support of python 2 from ckbytelist class, since python 2 is not supported anymore.

The performance issue can be illustrated with a simple benchmark command:

python3 -m timeit -s "import PyKCS11" "PyKCS11.ckbytelist(b'x'*100)"

For instance, on my system it now runs about six times faster compared to master.

@coveralls
Copy link

coveralls commented Aug 19, 2024

Coverage Status

coverage: 87.164% (-0.05%) from 87.212%
when pulling 6f7c704 on fuzzykat:feature/ckbytelist
into f198974 on LudovicRousseau:master.

@LudovicRousseau
Copy link
Owner

I propose to just remove support of Python 2 for ckbytelist

Python 2 is no more supported since at least f4cb36e

@fuzzykat
Copy link
Contributor Author

I propose to just remove support of Python 2 for ckbytelist

Python 2 is no more supported since at least f4cb36e

Done!

@fuzzykat fuzzykat changed the title Remove python version check from ckbytelist constructor Remove python 2 support from ckbytelist constructor Aug 19, 2024
@LudovicRousseau
Copy link
Owner

Merged in bfb4e01

Thanks

@fuzzykat fuzzykat deleted the feature/ckbytelist branch August 20, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants