GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-37348: optimize PyUnicode_FromString by methane · Pull Request #14273 · python/cpython

Conversation

@methane

@methane methane commented Jun 20, 2019 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

https://bugs.python.org/issue37348

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
methane added 2 commits June 21, 2019 00:57
@methane
bpo-37348: optimize PyUnicode_FromString for ASCII
ba4f73b
@methane
add news fragment
240310c
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Jun 20, 2019
@bedevere-bot bedevere-bot added the awaiting core review label Jun 20, 2019
vstinner
vstinner reviewed Jun 20, 2019
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this change is needed (why it makes the code faster): unicode_decode_utf8() already starts by decoding from ASCII. Is it a performance issue in ascii_decode()? Does _PyUnicodeWriter adds a small overhead which is significant here?

cc @serhiy-storchaka who knows well such hardcores micro-optimizations ;-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Objects/unicodeobject.c

while (u[len] != '\0') {
if (u[len] > 127) {
is_ascii = 0;

@vstinner vstinner Jun 20, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you reuse fast _Py_bytes_isascii() somehow here? It works on unsigned long words (64 bits) rather than working on bytes (8 bits): it should be 8x faster.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Objects/unicodeobject.c
if (is_ascii) {
return _PyUnicode_FromASCII(u, (Py_ssize_t)len);
}
return PyUnicode_DecodeUTF8Stateful(u, (Py_ssize_t)len, NULL, NULL);

@vstinner vstinner Jun 20, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not modifying PyUnicode_DecodeUTF8Stateful() to detect if the input string is ASCII, or your heuristic is faster? Is it because it make non-ASCII string decoding slower?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@methane methane closed this Jun 21, 2019
@methane
methane deleted the ascii-fromstring branch June 21, 2019 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@methane @vstinner @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.