Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
R High Performance Programming

You're reading from   R High Performance Programming Overcome performance difficulties in R with a range of exciting techniques and solutions

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781783989263
Length 176 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Tjhi W Chandra Tjhi W Chandra
Author Profile Icon Tjhi W Chandra
Tjhi W Chandra
Aloysius Shao Qin Lim Aloysius Shao Qin Lim
Author Profile Icon Aloysius Shao Qin Lim
Aloysius Shao Qin Lim
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Understanding R's Performance – Why Are R Programs Sometimes Slow? FREE CHAPTER 2. Profiling – Measuring Code's Performance 3. Simple Tweaks to Make R Run Faster 4. Using Compiled Code for Greater Speed 5. Using GPUs to Run R Even Faster 6. Simple Tweaks to Use Less RAM 7. Processing Large Datasets with Limited RAM 8. Multiplying Performance with Parallel Computing 9. Offloading Data Processing to Database Systems 10. R and Big Data Index

R requires all data to be loaded into memory

All data that is processed in R has to be fully loaded into the RAM. This means that once the data has been loaded, all of it is available for processing by the CPU, which is great for performance. On the other hand, it also means that the maximum size of data that you can process depends on the amount of free RAM available on your system. Remember that not all the RAM on your computer is available to R. The operating system, background processes, and any other applications that are running in the CPU also compete for the RAM. What is available for R to use might be a fraction of the total RAM installed on the system.

On top of that, R also requires free RAM to store the results of its computations. Depending on what kinds of computations you are performing, you might need the available RAM to be twice or even more times as large as the size of your data.

32-bit versions of R are also limited by the amount of RAM they can access. Depending on the operating system, they might be limited to 2 GB to 4 GB of RAM even when there is actually more RAM available. Furthermore, due to memory address limits, data structures in 32-bit versions of R can contain at most 231-1 = 2,147,483,647 elements. Because of these limits, you should use the 64-bit versions of R whenever you can.

Note

In all versions of R prior to 3.0, even 64-bit versions, vectors and other data structures faced this 2,147,483,647-element limit. If you have data that exceeds this size, you need to use a 64-bit version of R 3.0 or one of its later versions.

What happens when we try to load a dataset that is larger than the available RAM? Sometimes, the data loads successfully, but once the available RAM is used up, the operating system starts to swap the data in RAM into a swapfile on the hard disk. This is not a feature of R; it depends on the operating system. When this happens, R thinks that all the data has been loaded into the RAM when in fact the operating system is hard at work in the background swapping data between RAM and the swapfile on the disk. When such a situation occurs, we have a disk I/O bottleneck on top of the memory bottleneck. Because disk I/O is so slow (hard drive's speed is typically measured in milliseconds, while RAM's speed in nanoseconds), it can cause R to appear as if it is frozen or becomes unresponsive. Of the three performance limitations we looked at, disk I/O often has the largest impact on R's performance.

Chapter 6, Simple Tweaks to Use Less RAM and Chapter 7, Processing Large Datasets with Limited RAM will discuss how to optimize memory usage and work with datasets that are too large to fit into the memory.

You have been reading a chapter from
R High Performance Programming
Published in: Jan 2015
Publisher:
ISBN-13: 9781783989263
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image