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

return more memory from unicode objects to system #46574

Closed
nnorwitz mannequin opened this issue Mar 17, 2008 · 7 comments
Closed

return more memory from unicode objects to system #46574

nnorwitz mannequin opened this issue Mar 17, 2008 · 7 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@nnorwitz
Copy link
Mannequin

nnorwitz mannequin commented Mar 17, 2008

BPO 2321
Nosy @gvanrossum, @mitsuhiko, @coderanger
Files
  • uni.diff: unicode object
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-03-18.04:19:49.373>
    created_at = <Date 2008-03-17.15:48:22.103>
    labels = ['interpreter-core', 'performance']
    title = 'return more memory from unicode objects to system'
    updated_at = <Date 2008-03-18.04:21:44.656>
    user = 'https://bugs.python.org/nnorwitz'

    bugs.python.org fields:

    activity = <Date 2008-03-18.04:21:44.656>
    actor = 'nnorwitz'
    assignee = 'nnorwitz'
    closed = True
    closed_date = <Date 2008-03-18.04:19:49.373>
    closer = 'nnorwitz'
    components = ['Interpreter Core']
    creation = <Date 2008-03-17.15:48:22.103>
    creator = 'nnorwitz'
    dependencies = []
    files = ['9689']
    hgrepos = []
    issue_num = 2321
    keywords = ['patch']
    message_count = 7.0
    messages = ['63654', '63674', '63693', '63710', '63758', '63833', '63882']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'nnorwitz', 'MrJean1', 'aronacher', 'alecthomas', 'coderanger']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue2321'
    versions = ['Python 2.6', 'Python 2.5']

    @nnorwitz
    Copy link
    Mannequin Author

    nnorwitz mannequin commented Mar 17, 2008

    This patch returns more memory to the system when doing:

    >>> x = [unicode(i) for i in xrange(1000000)]
    >>> del x

    If the above code is done, the memory before and after is quite
    different. After this patch, the memory of the process as reported by
    the system (like top/ps) should be approximately the same

    @nnorwitz nnorwitz mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage labels Mar 17, 2008
    @alecthomas
    Copy link
    Mannequin

    alecthomas mannequin commented Mar 17, 2008

    Hi Neal,

    This seems to be a more general problem than just unicode.

    eg. Tuples:

    >> x = [(1, 2, 3, 4, i) for i in xrange(800000)]
    >> del x

    And user-defined objects:

    >>> class A(object):
    ...   def __init__(self):
    ...     self.x = random.random()
    >>> x = [A() for i in xrange(800000)]
    >>> del x

    Both exhibit the same behaviour. Naively to me it seems like using the
    custom allocator uniformly would fix this problem.

    @nnorwitz
    Copy link
    Mannequin Author

    nnorwitz mannequin commented Mar 17, 2008

    On Mon, Mar 17, 2008 at 11:55 AM, Alec Thomas <report@bugs.python.org> wrote:

    Alec Thomas <alec@swapoff.org> added the comment:

    Hi Neal,

    This seems to be a more general problem than just unicode.

    Kinda, sorta. The general issue is the pattern of memory
    allocation/deallocation. In the case of

    >> x = [(1, 2, 3, 4, i) for i in xrange(800000)]

    The memory that is not returned is in the integer free list. If this
    code is changed to:

    >> for x in ((1, 2, 3, 4, i) for i in xrange(800000)): pass

    That doesn't hold on to any extra memory. The problem is that holes
    are left in memory and a lot of it can't always be returned to the
    O/S. It can still be re-used by python.

    Both exhibit the same behaviour. Naively to me it seems like using the
    custom allocator uniformly would fix this problem.

    In general, we should find places (like unicode) that use PyMem_* (ie,
    system malloc) and replace them with PyObject_* (pymalloc). That
    should improve the behaviour, but there will always be some allocation
    patterns that will be suboptimal. Note that using pymalloc will only
    help for objects < 256 bytes. Larger objects are delegated to the
    system malloc and will still exhibit some of the bad problems.

    Alec, can you find places that are using the PyMem_* interface and
    create a patch to fix them. That would be great!

    @alecthomas
    Copy link
    Mannequin

    alecthomas mannequin commented Mar 17, 2008

    Alec, can you find places that are using the PyMem_* interface and
    create a patch to fix them. That would be great!

    Sure thing! I'll see if I can finish it today, but if not I'll work on
    it during the flight to Zurich tonight.

    @MrJean1
    Copy link
    Mannequin

    MrJean1 mannequin commented Mar 17, 2008

    Just for the record, the enhanced profiler source files in
    <http://bugs.python.org/issue2281\> and <http://bugs.python.org/issue2218\>
    do replace calls to malloc and free with PyObject_MALLOC resp. _FREE.

    @gvanrossum
    Copy link
    Member

    Looks good, Neal. Are you hesitant to check this in? I ran a little
    test showing that indeed it gives much more memory back to the system.

    @nnorwitz
    Copy link
    Mannequin Author

    nnorwitz mannequin commented Mar 18, 2008

    After discussing this with MvL, I'll check this patch into trunk and
    2.5. Alec, if you find other issues, please create a new patch.

    Committed revision 61458.
    Committed revision 61485. (2.5)

    @nnorwitz nnorwitz mannequin closed this as completed Mar 18, 2008
    @nnorwitz nnorwitz mannequin self-assigned this Mar 18, 2008
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant