((PLEASE EDIT HERE, IT IS A WIKI! BUT IT'S NOT AN ANSWER, IS A 2019 BIG-PICTURE))
REVIEWING THE MANY HYPOTHESIS:
Would this lag be a side effect of a Trojan scanning our keyboards?
It seems that it is not, but a double check is necessary: please report here any evidence (and procedures to check the evidence) on the Trojan hypothesis.
Evidence that is not an "external Trojan": the lag problem persist in the USB-Live and in fresh UBUNTU 18 installations — before to install any "external of the ISO" application.
PS: "internal" is introduced by release 18 ISO distribution... so, we can consider a bug, not a virus.
Would this lag caused by feature "Slow Keys"
It is another problem! It is a good first hypothesis, easy to test and discard.
NOTE: this page recives thousands pageviews, so, if you was looking for "Slow Keys", see this good (4 votes) answer and solution (or see this other page discussion).
Would this lag be a hardware lag problem?
No, see @TrinitronX comments demonstrating that it is not. All types of hardwares offer the same lag experience, it is not a "lag by hardware low performance".
Would this lag be a USB-driver problem?
Yes, a USB-keyboard problem, a bug or a conflict on the software of device-driver... But something that occurs mainly with old machines and/or old devices, when ported from UBUNTU v16 LTS to v18 LTS, beucause the lag not exist on v16 neither on modern devices.
Evidences: please check all comments and answers (and edit here listing it), they all talk about different USB devices.
CONCLUSION ABOUT OUR MAIN PROBLEM AND ITS CORRECT HYPOTHESIS:
THIS problem is the lag caused by change to some USB keyboards
This 2019 review of the question is about the USB keyboard's driver bug and its manifestation as a lag.
After ~1.5 years this question is stable and offers a general testimony about keyboard input lag: that it is a 1 second to 3 seconds lag, in general starting a section or change USB device (to non-USB). In all applications (e.g. terminal, Gedit, browser, somethimes login). It is a real bug in the UBUNTU 18 distribution.
How to detect/confirm that my problem is THIS problem?
Monitoring changes in the syslog during lag occurences by
tail -f /var/log/syslog
: open it in a terminal-window and in other window test to edit by USB keyboard and by original (onboard) keyboard. Collect evidences and compare here with the reported ones.
grep -i controller /var/log/syslog
must to show typical "ohci_hcd: USB" lines in your collected evidences.
grep -i ETC /var/log/syslog
you can use other words (e.g. "unhandled") instead "ETC" to check collected evidences.
OTHER USEFUL INFORMATION FOR ANSWERS AND DISCUSSIONS
Study cases, complete profile (system and hardware) where THIS lag problem occured.
CASE 1. It is a fresh UBUNTU 18 LTS, the machine is working fine with Ubuntu 16 LTS (in another partition), it is an old Samsung with Intel i3 core, SSD disk and RAM used as this free -m
command:
total used free shared buff/cache available
Mem: 3741 1466 1278 260 995 1794
Swap: 2047 0 2047
Monitoring changes in the syslog during lag occurences, main changes and other evidence:
tail -f /var/log/syslog
.
... /usr/lib/gdm3/gdm-x-session[1324]: (II) config/udev: Adding input device DELL Dell USB Entry Keyboard (/dev/input/event11)
... /usr/lib/gdm3/gdm-x-session[1324]: (**) DELL Dell USB Entry Keyboard: Applying InputClass "libinput keyboard catchall"
... /usr/lib/gdm3/gdm-x-session[1324]: (II) Using input driver 'libinput' for 'DELL Dell USB Entry Keyboard'
... /usr/lib/gdm3/gdm-x-session[1324]: (II) systemd-logind: got fd for /dev/input/event11 13:75 fd 47 paused 0
... /usr/lib/gdm3/gdm-x-session[1324]: (**) DELL Dell USB Entry Keyboard: always reports core events
... /usr/lib/gdm3/gdm-x-session[1324]: (**) Option "Device" "/dev/input/event11"
... /usr/lib/gdm3/gdm-x-session[1324]: (II) event11 - DELL Dell USB Entry Keyboard: is tagged by udev as: Keyboard
... /usr/lib/gdm3/gdm-x-session[1324]: (II) event11 - DELL Dell USB Entry Keyboard: device removed
... /usr/lib/gdm3/gdm-x-session[1324]: (**) Option "config_info" "udev:/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/0003:413C:2107.0002/input/input13/event11"
In this kind of experiments the main grep
s are:
grep -i HCI /var/log/syslog
... kernel: [ 3770.983036] usb 2-1.1: new low-speed USB device number 5 using ehci-pci
... kernel: [ 7084.642797] usb 2-1.1: new high-speed USB device number 6 using ehci-pci
... kernel: [ 1.141461] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
... kernel: [ 1.141471] ehci-pci: EHCI PCI platform driver
... kernel: [ 1.141981] ehci-pci 0000:00:1a.0: EHCI Host Controller
... kernel: [ 1.142001] ehci-pci 0000:00:1a.0: new USB bus registered, assigned bus number 1
... kernel: [ 1.142025] ehci-pci 0000:00:1a.0: debug port 2
... kernel: [ 1.146059] ehci-pci 0000:00:1a.0: cache line size of 64 is not supported
... kernel: [ 1.146091] ehci-pci 0000:00:1a.0: irq 16, io mem 0xfc806000
... kernel: [ 1.158091] ehci-pci 0000:00:1a.0: USB 2.0 started, EHCI 1.00
... kernel: [ 1.158232] usb usb1: Product: EHCI Host Controller
... kernel: [ 1.159065] ehci-pci 0000:00:1d.0: EHCI Host Controller
... kernel: [ 1.163101] ehci-pci 0000:00:1d.0: cache line size of 64 is not supported
... kernel: [ 1.178159] usb usb2: Manufacturer: Linux 5.0.0-37-generic ehci_hcd
... kernel: [ 1.178720] ehci-platform: EHCI generic platform driver
... kernel: [ 1.178738] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
... kernel: [ 1.178743] ohci-pci: OHCI PCI platform driver
... kernel: [ 1.178757] ohci-platform: OHCI generic platform driver
... kernel: [ 1.178768] uhci_hcd: USB Universal Host Controller Interface driver
... kernel: [ 1.467492] ahci 0000:00:1f.2: version 3.0
... kernel: [ 1.468810] scsi host0: ahci
... kernel: [ 1.502080] usb 1-1: new high-speed USB device number 2 using ehci-pci
... kernel: [ 477.859695] usb 2-1.2: new low-speed USB device number 5 using ehci-pci
grep -i controller /var/log/syslog
... kernel: [ 0.270587] acpiphp: ACPI Hot Plug PCI Controller Driver version: 0.5
... kernel: [ 1.120115] shpchp: Standard Hot Plug PCI Controller Driver version: 0.4
... kernel: [ 1.141461] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
... kernel: [ 1.141981] ehci-pci 0000:00:1a.0: EHCI Host Controller
... kernel: [ 1.158232] usb usb1: Product: EHCI Host Controller
... kernel: [ 1.159065] ehci-pci 0000:00:1d.0: EHCI Host Controller
... kernel: [ 1.178157] usb usb2: Product: EHCI Host Controller
...
grep -i controller /var/log/syslog
... kernel: [ 0.270587] acpiphp: ACPI Hot Plug PCI Controller Driver version: 0.5
... kernel: [ 1.120115] shpchp: Standard Hot Plug PCI Controller Driver version: 0.4
... kernel: [ 1.141461] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
... kernel: [ 1.141981] ehci-pci 0000:00:1a.0: EHCI Host Controller
... kernel: [ 1.158232] usb usb1: Product: EHCI Host Controller
... kernel: [ 1.178738] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
... kernel: [ 1.178768] uhci_hcd: USB Universal Host Controller Interface driver