Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up mapping of x,y to line number and column #48

Open
abegel opened this issue May 6, 2023 · 1 comment
Open

Speed up mapping of x,y to line number and column #48

abegel opened this issue May 6, 2023 · 1 comment

Comments

@abegel
Copy link

abegel commented May 6, 2023

Looking at the source code in xml_writer.cs, there are some very easy ways to optimize this code to run much faster.

  1. Instead of System.Windows.Forms.Timer class, which is from the Stone Age of C#, use the System.Diagnostics.Stopwatch class to make a timer. (https://tekeye.uk/visual_studio/high-speed-regular-events-in-c-sharp). Timer can't go faster than every 16 ms.
  2. getVSData() should be executed in its own thread instead of in the event thread. Spawn the thread when this addin is loaded. Every time the timerTick goes off, push the x,y,timestamp data into a thread-safe queue. The thread can drain this queue and process the x,y location.
  3. Have the getVSData() function write its mapping (line number, column) into a thread-safe queue.
  4. Disk access doesn't need to be in the event thread. Have another thread drain the output queue and write XML to disk.

This should remove significant bottlenecks from the code.

@abegel
Copy link
Author

abegel commented May 6, 2023

You'll also need to set the timer resolution of the application down to something smaller, like 1 ms instead of 15.6 ms (default).

https://stackoverflow.com/questions/3744032/why-are-net-timers-limited-to-15-ms-resolution
https://stackoverflow.com/questions/24839105/high-resolution-timer-in-c-sharp

You probably want to set this based on the eye tracker's frequency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant