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

Faster marshalling #67533

Closed
serhiy-storchaka opened this issue Jan 28, 2015 · 4 comments
Closed

Faster marshalling #67533

serhiy-storchaka opened this issue Jan 28, 2015 · 4 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@serhiy-storchaka
Copy link
Member

BPO 23344
Nosy @kristjanvalur, @serhiy-storchaka
Dependencies
  • bpo-23392: Add tests for marshal FILE* API
  • Files
  • marshal_faster_write.patch
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2015-02-11.15:51:27.406>
    created_at = <Date 2015-01-28.22:22:06.820>
    labels = ['interpreter-core', 'performance']
    title = 'Faster marshalling'
    updated_at = <Date 2015-02-11.15:51:27.405>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2015-02-11.15:51:27.405>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-02-11.15:51:27.406>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2015-01-28.22:22:06.820>
    creator = 'serhiy.storchaka'
    dependencies = ['23392']
    files = ['37898']
    hgrepos = []
    issue_num = 23344
    keywords = ['patch']
    message_count = 4.0
    messages = ['234920', '235347', '235747', '235752']
    nosy_count = 3.0
    nosy_names = ['kristjan.jonsson', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue23344'
    versions = ['Python 3.5']

    @serhiy-storchaka
    Copy link
    Member Author

    Currently writing marshalled data to buffer is not very efficient. Data is written byte by byte with testing conditions p->fp != NULL and p->ptr != p->end for every byte. Proposed patch makes writing to buffer faster.

    Benchmark results:

    $ ./python -m timeit -s "import marshal; d = compile(open('Lib/_pydecimal.py').read(), '_pydecimal.py', 'exec')" -- "marshal.dumps(d)"
    Unpatched: 100 loops, best of 3: 4.64 msec per loop
    Patched: 100 loops, best of 3: 3.39 msec per loop
    
    $ ./python -m timeit -s "import marshal; a = ['%010x' % i for i in range(10**4)]" -- "marshal.dumps(a)"
    Unpatched: 1000 loops, best of 3: 1.96 msec per loop
    Patched: 1000 loops, best of 3: 1.32 msec per loop
    
    $ ./python -m timeit -s "import marshal; a = ['%0100x' % i for i in range(10**4)]" -- "marshal.dumps(a)"
    Unpatched: 100 loops, best of 3: 10.3 msec per loop
    Patched: 100 loops, best of 3: 3.39 msec per loop

    @serhiy-storchaka serhiy-storchaka added interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage labels Jan 28, 2015
    @kristjanvalur
    Copy link
    Mannequin

    kristjanvalur mannequin commented Feb 3, 2015

    looks good to me, although it has been pointed out that marshal _write_ speed is less critical than read speed :)

    @serhiy-storchaka serhiy-storchaka self-assigned this Feb 4, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 11, 2015

    New changeset bb05f845e7dc by Serhiy Storchaka in branch 'default':
    Issue bpo-23344: marshal.dumps() is now 20-25% faster on average.
    https://hg.python.org/cpython/rev/bb05f845e7dc

    @serhiy-storchaka
    Copy link
    Member Author

    Thank you for your review Kristján. Together with bpo-20416 this increases dumping speed almost twice for typical module data and up to 5x for some data.

    @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