After Effects allocates RAM to play video and audio in the Timeline, Layer, or Footage panel at real-time speed. The number of frames that can be stored for real-time playback depends on the amount of RAM available and the settings in the Preview panel. The default preview behavior is configured to produce a preview that represents a real-time playback. When you press spacebar (the default keyboard shortcut), After Effects starts a preview with audio, and caches frames until the available RAM is filled.
Why doesn't After Effects preview in real-time like Premiere Pro?
After Effects is different than Premiere Pro when it comes to previewing.
In Premiere, if you have a 60-second sequence and hit Play, the playhead will reach the end of the sequence in exactly 60 seconds, even if Premiere has to skip frames to do so. This is not always the case in After Effects. If you have a 10-second composition in After Effects and hit Play, it may take 10 seconds, or it might take 17 seconds, or it might take 2 minutes and 43 seconds. Common to most motion graphic applications, After Effects will not skip frames - it will play every frame of video, even if it has to slow down playback to do so. But usually, on the second playthrough, it plays smoothly. [Source- Screenlight.tv Blog]
Under the hood, After Effects has a different architecture than Premiere Pro. As mentioned above, After Effects has to load every frame of the composition in the RAM before it can be previewed. That's why it's recommended to limit the length of the composition to a few seconds because working in a lengthy composition means your computer has to process thousands of frames. Thus, putting a lot of strain on your computer and making it difficult to preview in real-time.