Issue1480

classification
Title: String accumulation is quadratic in Jython in a case that CPython is linear
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: fwierzbicki, ssteiner, thobes, zyasoft
Priority: low Keywords: RFE

Created on 2009-09-29.11:03:40 by ssteiner, last changed 2014-06-19.07:46:47 by zyasoft.

Messages
msg5202 (view) Author: simon steiner (ssteiner) Date: 2009-09-29.11:03:40
myfile is a 1MB text file. This takes few seconds on python or jep.

<script language="jython" setbeans="false">
<![CDATA[
t = ''
f = open(r'myfile')
for l in f:
    t = t + l
f.close()
]]>
</script>
msg5203 (view) Author: simon steiner (ssteiner) Date: 2009-09-29.11:11:47
Seems i need to use StringIO
msg5204 (view) Author: Jim Baker (zyasoft) Date: 2009-09-29.16:07:06
Use StringIO (as ssteiner suggests), cStringIO, or accumulate in a list, 
then join together.

CPython now optimizes this one case of accumulating strings so that it's 
not quadratic in performance. Naively, it is an optimization that we 
should be able to do too once we have a smarter compiler (the SSA work), 
although it may not be a high priority.
msg8741 (view) Author: Jim Baker (zyasoft) Date: 2014-06-19.07:46:47
No smarter compiler forthcoming for this type of work (the SSA work didn't pan out). CPython can do certain types of local optimizations around loops that are not possible under the GC model used by Java and consequently Jython.
History
Date User Action Args
2014-06-19 07:46:47zyasoftsetstatus: open -> closed
resolution: remind -> wont fix
messages: + msg8741
2013-02-19 19:07:17fwierzbickisetnosy: + fwierzbicki
resolution: remind
versions: + Jython 2.7, - 2.5.0
2009-09-29 16:07:32zyasoftsetpriority: low
2009-09-29 16:07:06zyasoftsetkeywords: + RFE
nosy: + zyasoft, thobes
messages: + msg5204
title: Loop through file is slow -> String accumulation is quadratic in Jython in a case that CPython is linear
2009-09-29 11:11:47ssteinersetmessages: + msg5203
2009-09-29 11:03:40ssteinercreate