[rkward-tracker] [ rkward-Feature Requests-1810061 ] Speed up assignments in globalenv()
SourceForge.net
noreply at sourceforge.net
Tue Jun 8 14:31:54 UTC 2010
Feature Requests item #1810061, was opened at 2007-10-09 12:03
Message generated for change (Comment added) made by tfry
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=459010&aid=1810061&group_id=50231
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Priority: 5
Private: No
Submitted By: Thomas Friedrichsmeier (tfry)
Assigned to: Nobody/Anonymous (nobody)
Summary: Speed up assignments in globalenv()
Initial Comment:
Assignments inside globalenv() are slow due to modification detection. Run this code:
# first create an object in a single command
x <- 1
# now assign to it many times
for (i in 1:100000) x <- 2
# in contrast, try this:
local ({for (i in 1:100000) x <- 2; x <<- x})
The latter is tremendously faster. In a plain R session, there is no such difference.
Probably we can improve on this by implementing .rk.watch.symbol(), and esp. the watch function created by .rk.make.watch.f() in C, and also fine-tuning it in the process.
----------------------------------------------------------------------
>Comment By: Thomas Friedrichsmeier (tfry)
Date: 2010-06-08 16:31
Message:
Here's a new idea on how to approach this problem:
1) Instead of using active bindings for all objects, use active bindings
only for object which are already active bindings (i.e. add a layer of
indirection to those as before).
2) For all other objects, copy them to a storage environment as before,
but then:
3) After each command simply check, whether the object in globalenv() is
still the same as in the storage envionrment. Simply pointer comparison
should be good enough!
----------------------------------------------------------------------
Comment By: Thomas Friedrichsmeier (tfry)
Date: 2007-10-09 17:28
Message:
Logged In: YES
user_id=300591
Originator: YES
The attached code is not quite correct (dealing with promises) or clean,
and will need further adjustments in .rk.watch.globalenv(), but illustrates
a first approach.
This speeds up the testcase by around factor 2.5, but is still 30-40 times
slower than without watching the object (note that this isn't really a real
world testcase, though, in that it's really just assignments without any
computation). For assignments only (not the reads), more than half of the
time is spent inside the C callback, and we can likely cut down on this
considerably.
The markable difference between reads and writes (beyond the times spent
in .Call) suggest that the "<<-" operator is still fairly expensive. If we
could implement the entire assignment part in C, then we might gain even
more performance. We key would be to know where to look for x, and assign
there, directly.
File Added: watchtest.R
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=459010&aid=1810061&group_id=50231
More information about the rkward-tracker
mailing list