Jump to content
NHL'94 Forums

GUIDE: RetroArch and dealing with lag


chaos

Recommended Posts

There are 2 major forms of latency (or lag, whichever you'd like to call it):

 

Input Latency - The delay from pressing a button, to the display of that button action on the screen. 

Network Latency - The delay in communication from one computer to another. In our case, the amount of time it takes to for one player's button press to show up on the other player's screen.

Latency is usually displayed in ms (milliseconds).

 

An emulator displays video by frames. Most emulators use an ~60Hz refresh rate (similar to the consoles they emulate), which means it displays 60 video frames per second. The video on the screen refreshes every 16.7ms (1 second / 60 frames = 16.7ms). So, the fastest an emulator can show a change on the screen is 16.7ms.

This may seem like very little time, but in regards to computer processing, this is a ton of time. A lot of things happen within those 16.7ms, one of which is preparing for the next video frame.

Input Latency

The emulator checks for controller input during a specific time during a frame. If the input arrives before that time, it will update the video on the screen. How soon you see a reaction to your input is called the input latency.

Many things can factor into this: 

  • Controller - Your USB/Bluetooth/wireless controller polls the button inputs every couple of ms. Some poll quicker than others (2-4 ms), some take longer than others (11-16ms). This contributes to input lag. On top of that, the PC will poll the controller, which also contributes to input lag (though this is usually 1-2 ms). So, when you press the button, the controller polls the buttons to see what was pressed, and then the PC polls the controller to get the input. This is not instant.
  • Emulator - Depending on how well the emulator is coded, some of them can contribute to input lag. It can receive the input from the PC, but it may take a frame or 2 before it updates the video to show the input.
  • Display - Depending on your monitor or TV, there could be a delay added. HDTVs especially, since there is some upscaling of the video involved in order to display it (this can add a few frames). Computer monitors are usually lag-free.

 

Regardless of all the latency added above, the emulator still checks for input every 16.7ms. So if you press the button, if it gets to the emulator in time, it will display it. The problem is this: It only checks every 16.7ms. So, if you press the button mid-frame (8ms), and your input latency adds up to 10ms, the total is 18ms (10ms latency, 8ms to press the button), and you will miss the frame. Your input has to wait for the next frame to show up.

 The best way to think of the above is this way: Imagine you need to get on the bus. A bus comes by every 16.7ms to pick people up. It takes 10ms for you to get to the bus stop from your house (your latency). Depending on the time you leave your house (press a button), will depend on what bus (frame) you make.  

If you are curious as to the input lag of your controller (the first part of above), you can look it up on the internet. A lot of people have done tests of controllers. For example, the wired retro-bit controllers come in around 10ms, where as a wired 8bitdo M30 2.4g has about 3-4ms.

 

Network Latency

Network latency is the amount of time it takes for communication between 2 PCs. This comes into effect during Netplay, when 2 PCs are sending inputs back and forth. 

Latency increases with distance (the further the signal has to travel, the more latency there most likely will be), but there are many other factors that can cause latency:

  • Wifi - A wireless signal from a PC to a router can be affected by many things. Walls, interference from microwaves (microwaves use the same frequency as most Wifi routers), interference from wireless landline phones (same frequency), distance from PC to router, devices on Wifi, etc. You can have the fastest internet and Wifi router in the world, but it will not make a difference. Wifi adds lag, and since it isn't consistent lag, it makes it even worse.
  • Jitter - Your internet speed is not important when it comes to gaming. You can have 1GBit download and upload speeds, but what matters most is jitter, or stability. Input lag is usually consistent, in other words, stable. Your eye can easily adjust to it after a minute or so. Network jitter causes instability, where the network lag constantly changes. There are many things that can cause this, though most are out of your hands. You can check your network jitter using online tests such as speedtest.net. Note, this will change (you will get different results every time you run it), but the goal is to have jitter that is less than 8ms or so. One of the only ways you can control jitter is by using a wired connection for internet, between your PC and router. Other than that, you are at the mercy of your Internet Service Provider (ISP).
  • Local Network Load - This is a problem again you may have some control over. The amount of devices using internet on your local network can cause a load on the router, where the router has to decide what devices to let through at a given time. Sometimes, your PC will be at the top of the list, sometimes on the bottom. The router decides what is most important. Sometimes, some routers have settings that give priority to gaming. Usually, this isn't much of a problem, but it could be.
  • ISP Network Load - You have no control over this. This depends on how many people are using the internet at a given time. In a case when a pandemic is going on, internet usage goes up, causes a network load, and everything slows down. Peak times (after work hours) will also cause issues with network traffic. 

 

Some people just have crappy internet service providers, and it might be their only option. In these cases, you just have to limit what you can. Again, speed doesn't matter, this game could be played using a 1200 baud modem no problems. The amount of data passed between PCs is just inputs, and occasionally save states. The most important thing is stability. If the Network Latency is constant, it can be dealt with easier than if it is constantly changing.

 

Both Input Latency and Network Latency are added together when it comes to Netplay. So if we use our bus analogy:

Imagine you need to get on the bus. A bus comes by every 16.7ms to pick people up. It takes 10ms for you to get to the bus stop from your house (your input latency). But now, there's traffic along the way (your network latency). Depending on the time you leave your house (press a button), and depending on how bad the traffic is at that time (network latency), will determine what bus you get on (what frame).

 

 RetroArch Netplay

Like I said above, your Input Latency (which is local to you) and Network Latency (between you and your opponent) affect your Netplay experience. 

RetroArch netplay, the way it works in a nutshell, is it checks frame by frame to see if it receives an input from the opponent. It also keeps track of what frame you and your opponent are on, and compares. When you connect to each other, it starts frame counting. So, when you press the B button on Frame 123, it sends that information to your opponent. When your opponent is on Frame 123, it receives your B button press, and shows it on the screen on the next frame (124), just when it would show on yours as well. In a perfect world, every button press on a frame would be registered on the same frame for your opponent, without problems.

But, what happens when you press your B button and it's showing your pass on Frame 123, but it doesn't get to your opponent until Frame 125? This is the effect of latency. What RA does in this case, is rewind to Frame 123, show your B button press, and continue. Now in this case, there is 2 frames of lag (which is ~33ms). The rewind may go unnoticed in this case. But, lets say the frame difference was 10 frames. That's 166.7ms. That may be noticeable to  the player. In this case, what they see is a skip, or "rubber-banding" where the skaters rewind back 10 frames, then continue. (Note: more goes on than just rewind, just keeping it simple here)

The short frame rewinds make it seem like input lag. Many players complaining about input lag are probably experiencing this. The larger frame rewinds are more noticeable and look like skips.

In other emulators, what would happen in this case, is the game would stutter and hang until one side caught up to the other. If the frame difference was large, the game would de-sync.

 

 Input Latency Frames and Run-Ahead

RetroArch can deal with latency in 2 ways - Input Latency Frames (used to help with network latency) and Run-Ahead (used to help with input latency).

Remember, Netplay expect the input from each player to arrive on the same frame. This is unrealistic. In some cases, when people playing against each other are very close geographically, this is possible (as long as all latency equals to less than a frame - 16.7ms, this works). In cases when playing across North America, expect network latency to be in the 20-80ms range.

Adding Input Latency Frames allows some time for Netplay to expect the input. If we add 2 Input Latency Frames, for example, when we press B on Frame 123, it sends the press on Frame 123, but delays showing it until Frame 126 (pressed on 123, would originally show on 124. 124 +2 frames = 126). This way, the opponent's PC can wait for the input on Frame 125, showing it on 126, giving it 3 frames total of travel (Frame 123, 124, 125).

Gens Kaillera Netplay and ZSNES both add 2 input latency frames automatically. Gens adjusts by adding more if needed (depends on ping).

By default, Input Latency Frames is set to 0 in RA.

 

Run-Ahead works locally, by removing input latency frames. By turning Run-Ahead on, you remove at least 1 frame of input latency (you can set it higher if you'd like). It's one of best features of RA. By default, it's turned off.

 

TL;DR:

So how can we use these to help improve Netplay experience? We can add Input Latency Frames, and remove some of them locally using Run-Ahead, to give us a near lag-free (in most cases) experience.

Example:

  • If we set Input Latency Frames to 2, and set Run-Ahead to 1, we essentially add 1 frame of input latency locally (2 input frames - 1 run-ahead frame = 1 total).
  • This gives the network 2 frames to play with as far as receiving data, but we only see a difference of 1 frame while playing. This is not noticeable. Even 2 frames is hard to notice.
  • NOTE: Adding Run-Ahead frames becomes CPU intensive. You can experiment with it, but 1 or 2 frames should be more than enough.
  • NOTE: When it comes to adding Input Latency Frames, both players have to have this set to the same value. Confer with your opponent beforehand as to how many you will set.
  • Run-Ahead is local only, so this doesn't matter if the values are different between players.

 

Setting Input Latency Frames

  1. Start RetroArch
  2. Discuss with your opponent how many latency frames you'll be using (I recommend starting with 1 or 2, that should be enough in most cases).
  3. Once decided, go to Netplay->Network.
  4. Set Input Latency Frames to the value decided (2 as shown below).

Input Latency Frames.png

NOTE: Leave "Input Latency Frames Range" to 0. Only set the Input Latency Frames. Also, the Input Latency Frames setting is saved when exiting RA. So make sure you check it before playing, if you'd like to change it again.

 

Enabling Run-Ahead

  1. Start RA.
  2. Go to Settings-Latency
  3. Turn "Run-Ahead to Reduce Latency" to ON.

Run-Ahead.png

 

I recommend using 2 Input Latency Frames, and 1 Run-Ahead Frame as a starting point. Switch to 1 Input Latency Frame when playing someone who is closer to you. Again, confer with your opponent, as it's important that your Input Latency Frames are the same value!

  • Thanks 5
  • Like 1
Link to comment
Share on other sites

Also, the most important thing is your local FPS (or frame rate). This should be very close to 60Hz, usually bouncing around in the 59-60Hz range. If you do not see this type of frame rate, check the troubleshooting thread! 

 

You can check the frame rate by using the F3 key (or Shift-F3, or Fn-F3, depending on your keyboard). You will see an FPS display in the top right of RetroArch. I recommend leaving this running all the time, so you can monitor it.

  • Thanks 2
  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Quick Tips:
 

Wi-Fi

  • Disconnect from your wifi. Even if you have the ethernet cable plugged in, often your computer will favour using wifi.
  • DON'T USE WIFI

Laptops

  • Plug in to a power source. If you run off battery, the laptop may use a low-power mode and be slower.
  • If you need to run on battery, then use the Power Options on the computer to run in High Performance mode.

General Internet:

  • Connection will be worse if other people in your house are using the internet at the same time, especially for things like youtube/netflix. Try to play when family are not watching netflix/youtube.
  • Go to this site (https://speed.cloudflare.com/) and observe the "latency" and "jitter" measures. Latency corresponds to lag(delay). Jitter corresponds to lag-spikes, which is the worst thing.
  • Ideally your jitter should be very low, like under 5ms.
  • Don't say "I've got a 100Gbps connection!" and think your connection is great. Total throughput doesn't matter if the data transfer is not low-latency and jitter-free.

Anti-Virus

  • Uninstall/Disable Norton anti-virus/firewall. It goes overboard and slows down the data packets coming in to the emulator, causing lag. "Windows Defender" is fine and free (build in to windows). If you can figure out how to add an exception in Norton so it doesn't affect your RetroArch executable, you can do that instead (and you'll need to do it every time you update RetroArch to a new version). Same with McAfee, too... you know it's not what you need when they try so hard to give it away like an extended warranty on a toaster.

Frame Rate Counter

  • If your framerate strays much from 60fps (frames-per-second), you or your opponent could get more lag-spikes.
  • To toggle framerate display, press the F3 key (or Shift+f3 or Fn+F3 depending on your keyboard)
  • To get a better(accurate) framerate count: Go to Settings->On Screen Display->On Screen Notifications and change the FPS framecount from 256 to something like 60

Video Filter

  • In my experience, the RA "Video Filter"s are SLOW, so don't use them. If you have accidentally selected one, use the Start button or Space key to clear the filter.
  • image.png

Laptops

  • This is my opinion.. it's your money, do what you want.
  • Cheap laptops are garbage, from day 1. Suggestions:
  • Don't buy anything under US$450 / CA$600 new. (If you really must get something cheaper, get it Used but also obeying the following specs)
  • Make sure it has at least 8GB of RAM. If no video card, try to get "dual channel" RAM (e.g. "2x4GB" is 8GB of dual-channel RAM), to avoid RAM access conflict between the CPU and integrated graphics.
  • As a rule of thumb, personally I would only consider Intel i3/i5/i7 CPUs. No Celeron, Athlon, Pentium Gold, A10, Atom.... Removed from recommendation: AMD Ryzen (top-of-the-line chip but apparently doesn't handle RetroArch well.. NOTE: Getting dual-channel RAM may fix this?).
  • The hard drive should be a SSD, not HDD.
  • Screen resolution: at least 1920x1080 (Full HD, FHD) unless you're getting a really small screen (<=13").
  • NO CHROMEBOOKS. It's not a "real" computer for running software. It's a 300$ web browser.
  • Like 2
Link to comment
Share on other sites

I'd prob stay away from Ryzen CPUs in laptops. Some guys that are suffering from frame rate drops when turning on hosting have Ryzens. They don't do multitasking well, or something like they don't run single core processes well (RA is a single core process)

Link to comment
Share on other sites

14 minutes ago, chaos said:

I'd prob stay away from Ryzen CPUs in laptops. Some guys that are suffering from frame rate drops when turning on hosting have Ryzens. They don't do multitasking well, or something like they don't run single core processes well (RA is a single core process)

OK, thanks! Removed.

Link to comment
Share on other sites

28 minutes ago, chaos said:

I'd prob stay away from Ryzen CPUs in laptops. Some guys that are suffering from frame rate drops when turning on hosting have Ryzens. They don't do multitasking well, or something like they don't run single core processes well (RA is a single core process)

Thoughts on the "threaded video" option in RA for dealing with this?

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 years later...
On 11/28/2020 at 4:25 PM, smozoma said:

Quick Tips:
 

    Wi-Fi

    • Disconnect from your wifi. Even if you have the ethernet cable plugged in, often your computer will favour using wifi.
    • DON'T USE WIFI

    Laptops

    • Plug in to a power source. If you run off battery, the laptop may use a low-power mode and be slower.
    • If you need to run on battery, then use the Power Options on the computer to run in High Performance mode.

    General Internet:

    • Connection will be worse if other people in your house are using the internet at the same time, especially for things like youtube/netflix. Try to play when family are not watching netflix/youtube.
    • Go to this site (https://speed.cloudflare.com/) and observe the "latency" and "jitter" measures. Latency corresponds to lag(delay). Jitter corresponds to lag-spikes, which is the worst thing.
    • Ideally your jitter should be very low, like under 5ms.
    • Don't say "I've got a 100Gbps connection!" and think your connection is great. Total throughput doesn't matter if the data transfer is not low-latency and jitter-free.

    Anti-Virus

    • Uninstall/Disable Norton anti-virus/firewall. It goes overboard and slows down the data packets coming in to the emulator, causing lag. "Windows Defender" is fine and free (build in to windows). If you can figure out how to add an exception in Norton so it doesn't affect your RetroArch executable, you can do that instead (and you'll need to do it every time you update RetroArch to a new version). Same with McAfee, too... you know it's not what you need when they try so hard to give it away like an extended warranty on a toaster.

    Frame Rate Counter

    • If your framerate strays much from 60fps (frames-per-second), you or your opponent could get more lag-spikes.
    • To toggle framerate display, press the F3 key (or Shift+f3 or Fn+F3 depending on your keyboard)
    • To get a better(accurate) framerate count: Go to Settings->On Screen Display->On Screen Notifications and change the FPS framecount from 256 to something like 60

    Video Filter

    • In my experience, the RA "Video Filter"s are SLOW, so don't use them. If you have accidentally selected one, use the Start button or Space key to clear the filter.
    • image.png

    Laptops

    • This is my opinion.. it's your money, do what you want.
    • Cheap laptops are garbage, from day 1. Suggestions:
    • Don't buy anything under US$450 / CA$600 new. (If you really must get something cheaper, get it Used but also obeying the following specs)
    • Make sure it has at least 8GB of RAM
    • As a rule of thumb, personally I would only consider Intel i3/i5/i7 CPUs. No Celeron, Athlon, Pentium Gold, A10, Atom.... Removed from recommendation: AMD Ryzen (top-of-the-line chip but apparently doesn't handle RetroArch well).
    • Screen resolution: at least 1920x1080 (Full HD, FHD) unless you're getting a really small screen (<=13").
    • NO CHROMEBOOKS. It's not a "real" computer for running software. It's a 300$ web browser.

    Hah! Ironically, I stumbled across this thread from DuckDuckGo, while looking for info on optimizing my Neo Geo core. Great explanation on latency controls above, better than most stuff I could find, presumably why it showed Ip so high in my search rankings. Plus the advice comes from guys I already trust. 
     

    Thought I’d throw in a +1 to Smozoma’s words on laptops. Every sub $500 machine I’ve seen is essentially a dedicated web browser, and a lost cause for being a true multifunction computing tool. They cut so many quarters on design and production, that you can actually coax better performance running off of a high quality phone or tablet. No disrespect to anyone who is limited by budget, just be realistic about the results you can expect if you’re limited to such a device.

    I’m sure Smoz meant to say this, but obviously intel i9 chips are great.

    if you’re buying a new laptop, for most people the i5 is actually ideal, because of how it is engineered to be a jack of all trades. If you’re the sort of person who would benefit from an i7 or i9, you already know who you are and are more than capable of looking up which varient of each chip would be ideal for you.  

    I’m told that the new generation of AMD mobile CPUs are respectable now, but I have no idea if that extends to Retroarch performance. 
     

    But let’s say that you’re on a sub optimal machine or a machine that’s giving you issues. Beyond Norton, McAfee etc, just make sure that you have as little running as possible in the background on your machine. On a Mac, launch your Activity Monitor (I think the equivalent on Windows is called Task Manager), and make sure nothing superfluous is running, that may suddenly decide to check for updates, or whatever. You can also use a free open source firewall like LuLu to lockdown all outgoing access on your machine, so that nothing else is compromising your outgoing connection latency. Lastly, you could go full hardcore and create a clean user account dedicated to playing games, with no superfluous software installed or authorized to run. 
     

     

    • Thanks 2
    Link to comment
    Share on other sites

    • 1 month later...
    • 3 weeks later...
    On 11/28/2020 at 4:51 PM, chaos said:

    I'd prob stay away from Ryzen CPUs in laptops. Some guys that are suffering from frame rate drops when turning on hosting have Ryzens. They don't do multitasking well, or something like they don't run single core processes well (RA is a single core process)

    I found a benchmark article today that showed that AMD chips (and Intel, to a lesser degree) have a significant performance bottleneck with single-channel RAM and integrated graphics (i.e. no graphics card). Upgrading to dual-channel RAM gives about a 75% performance increase for AMD, 25% for intel.

    "single channel RAM" means only 1 stick of RAM. "dual channel RAM" means 2 paired sticks of RAM. The theory here is that a single channel creates a bottleneck for the CPU vs the integrated/onboard GPU when gaming since they must use the same RAM.

    I also see AMD Ryzen benchmarks showing a 30-50% performance increase even WITH a video card. However also not sure RetroArch is intensive enough for this to make a difference...

    But if buying a new laptop, especially without a video card, I think it makes sense to make sure to get dual channel RAM since it shouldn't cost much more.

    How to find out if you have single- or dual-channel RAM (without opening up your computer case). You can probably upgrade for ~$40-$50

     

    • Like 1
    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...