Code

Opened 8 months ago

Closed 8 months ago

#21052 closed Cleanup/optimization (fixed)

force_bytes should handle the common case first like force_text

Reported by: aaugustin Owned by: nobody
Component: Utilities Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The patch I'm about to commit makes force_bytes twice as fast in the common case — and twice as slow when it's called with a memoryview, but we don't use them that often in Django.

Before:

% python -m timeit -s 'from django.utils.encoding import force_bytes' 'force_bytes(b"")' ~/Documents/dev/django
1000000 loops, best of 3: 0.705 usec per loop

After:

% python -m timeit -s 'from django.utils.encoding import force_bytes' 'force_bytes(b"")' ~/Documents/dev/django
1000000 loops, best of 3: 0.376 usec per loop

Attachments (0)

Change History (1)

comment:1 Changed 8 months ago by Aymeric Augustin <aymeric.augustin@…>

  • Resolution set to fixed
  • Status changed from new to closed

In b80be68e088f56f5b2ab5371b92a478a14937e8b:

Fixed #21052 -- Small performance optimization.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.