[R-pkg-devel] Searching examples in source code

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Sun May 8 22:29:10 CEST 2022


On 08/05/2022 3:52 p.m., Ben Engbers wrote:
> 
> 
> Op 08-05-2022 om 21:15 schreef Joshua Ulrich:
>> Hi Ben,
>>
>> On Sat, May 7, 2022 at 4:24 PM Ben Engbers <Ben.Engbers using be-logical.nl> wrote:
>>>
>>> Hi,
>>>
> 
>> I strongly recommend you profile your code to determine where there
>> are performance bottlenecks before writing any new code. Especially
>> before adding compiled code to your package.
>>
>> The infamous Knuth quote:
>> "We should forget about small efficiencies, say about 97% of the time:
>> premature optimization is the root of all evil. Yet we should not pass
>> up our opportunities in that critical 3%. A good programmer will not
>> be lulled into complacency by such reasoning, he will be wise to look
>> carefully at the critical code; but only after that code has been
>> identified."
> 
> This reminds me of Occams's razor ;-) If you have the choice between
> good working simple code or more complex code which might perform
> slightly better, the simple code is to be preferred.
> 
> I don't remember if it was because the package is based on R6 object
> orientation or if it was because the client is based on a client-server
> architecture. I do know that profiling did not add much information.
> 
> And a quick search for "R R6 profiling" shows that R6 applications
> cannot yet be examined using a profiler ;-(.

I think that isn't completely true.  One link I read said that by 
default the profiler code doesn't know function names, but it should 
still know line numbers if you kept them in your source and set 
`line.profiling` to TRUE when you run Rprof().  Setting that to TRUE 
makes the profiling output contain much more information.

I don't have a good example to demonstrate this, and I don't know if 
RStudio's post-processing of profiler output knows how to interpret this 
extra information, but the base summaryRprof() will show it if you ask 
for it, and a bad example I ran that isn't easily sharable shows that it 
does display line numbers in R6 source.


Duncan Murdoch



More information about the R-package-devel mailing list