Differences between revisions 5 and 6
Revision 5 as of 2006-10-11 00:06:26
Size: 2577
Comment:
Revision 6 as of 2006-10-14 13:40:42
Size: 3809
Comment:
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
 * Fastest option:
Line 23: Line 22:
 * currently non-free
 * supposed to be very fast
 * drop-in ?
 * GPLed (not announced yet)
 * faster than malloc/PyMem_Malloc etc.
{{{#!python
sage: x = 3; y = 5 # malloc (GMP default)
sage: timeit _ = x + y
100000 loops, best of 3: 8.14 microseconds per loop
sage: timeit _ = x + y
100000 loops, best of 3: 8.05 microseconds per loop

sage: sage.rings.integer.pmem_malloc()

sage: timeit _ = x + y # PyMem_Malloc
100000 loops, best of 3: 8.27 microseconds per loop
sage: x = 3; y = 5
sage: timeit _ = x + y
100000 loops, best of 3: 8.21 microseconds per loop

sage: omalloc_malloc()

sage: timeit _ = x + y # omalloc
100000 loops, best of 3: 7.55 microseconds per loop
sage: timeit _ = x + y
100000 loops, best of 3: 7.55 microseconds per loop
}}}
Larger integers:
{{{#!python
sage: x =
45234723458934634056310653251305043576435013985134515643531450714359863148659136951369851836545643565

sage: y =
23423964523462384234234234872345623645623452345283548234652365482348562346523642348263486234954534554

sage: timeit _ = x + y #malloc
100000 loops, best of 3: 8.3 microseconds per loop

sage: sage.rings.integer.pmem_malloc()

sage: timeit _ = x + y #PyMem_Malloc
100000 loops, best of 3: 8.58 microseconds per loop

sage: omalloc_malloc()

sage: timeit _ = x + y # omalloc
100000 loops, best of 3: 7.58 microseconds per loop
}}}

Malloc Replacements

This page describes possible malloc replacements to be used for memory management in SAGE which is not directly controlled by Python such as manual malloc/realloc calls, the GMP library etc..

Introduction

  • Benchmarks performed on my ([:MartinAlbrecht:malb]) 1200 Mhz Pentium 3 notebook running vanilla SAGE 1.4

malloc

   1 sage: x = 3; y = 5
   2 
   3 sage: timeit _ = x + y
   4 100000 loops, best of 3: 7.37 mircoseconds per loop

PyMem_Malloc

The Python memory manager does keep track of some previous allocated, unused, but not yet freed blocks so it should be faster than malloc itself. It is currently used in GMP and Pyrex code in SAGE.

OMalloc

  • GPLed (not announced yet)
  • faster than malloc/PyMem_Malloc etc.

   1 sage: x = 3; y = 5 #  malloc (GMP default)
   2 sage: timeit _ = x + y
   3 100000 loops, best of 3: 8.14 microseconds per loop
   4 sage: timeit _ = x + y
   5 100000 loops, best of 3: 8.05 microseconds per loop
   6 
   7 sage: sage.rings.integer.pmem_malloc()
   8 
   9 sage: timeit _ = x + y # PyMem_Malloc
  10 100000 loops, best of 3: 8.27 microseconds per loop
  11 sage: x = 3; y = 5
  12 sage: timeit _ = x + y
  13 100000 loops, best of 3: 8.21 microseconds per loop
  14 
  15 sage: omalloc_malloc() 
  16 
  17 sage: timeit _ = x + y # omalloc
  18 100000 loops, best of 3: 7.55 microseconds per loop
  19 sage: timeit _ = x + y
  20 100000 loops, best of 3: 7.55 microseconds per loop

Larger integers:

   1 sage: x = 
   2 45234723458934634056310653251305043576435013985134515643531450714359863148659136951369851836545643565
   3 
   4 sage: y = 
   5 23423964523462384234234234872345623645623452345283548234652365482348562346523642348263486234954534554
   6 
   7 sage: timeit _ = x + y #malloc
   8 100000 loops, best of 3: 8.3 microseconds per loop
   9 
  10 sage: sage.rings.integer.pmem_malloc()
  11 
  12 sage: timeit _ = x + y #PyMem_Malloc
  13 100000 loops, best of 3: 8.58 microseconds per loop
  14 
  15 sage: omalloc_malloc() 
  16 
  17 sage: timeit _ = x + y # omalloc
  18 100000 loops, best of 3: 7.58 microseconds per loop

DLMalloc

  • LGPL
  • used by OMalloc
  • unsure what it does

default libCF Memory Manager

  • GPL
  • seems to be faster for Integer addition than Python's manager

   1 sage: from sage.memory import * #only in my (malb) working copy
   2 
   3 # PyMem_Malloc
   4 sage: x = 5; y = 3
   5 sage: %timeit _ = x+y
   6 100000 loops, best of 3: 8.15 microseconds per loop
   7 
   8 # default libCF memory manager
   9 sage: memman_malloc()
  10 sage: %timeit _ = x+y
  11 100000 loops, best of 3: 7.36 microseconds per loop

libCF new Memory Manager

  • GPL
  • crashed on me ([:MartinAlbrecht:malb]) when trying to use it from withing SAGE

GivMM

  • GPL
  • "Short description of the Givaro memory mechanism: each request of sz bytes returns the smallest bloc that contains at least sz bytes. Each bloc begins by a private data used to store size information or a pointer. All free blocs are linked in list. The allocation algorithm search in the corresponding list a free bloc, before call the system "malloc" routine. 512 different sizes of bloc are predefined. The maximum bloc size is 8054880 bytes. For higher bloc, the manager directly call malloc/free of the underlaying system."
  • Seems to be slower than PyMem_Malloc for Integer addition

   1 sage: from sage.memory import *
   2 sage: x = 5; y = 3
   3 
   4 # PyMem_Malloc
   5 sage: %timeit _ = x+y
   6 100000 loops, best of 3: 8.15 microseconds per loop
   7 
   8 # GivaroMM
   9 sage: givaro_malloc()
  10 sage: %timeit _ = x+y
  11 100000 loops, best of 3: 8.36 microseconds per loop