From 4735cd195b320a70b3d17962e86219e595b3d045 Mon Sep 17 00:00:00 2001 From: Charlie Powell <31997505+cp2004@users.noreply.github.com> Date: Sat, 19 Feb 2022 16:41:09 +0000 Subject: [PATCH] :zap: Reduce gcode viewer memory usage when loading file --- src/octoprint/plugins/gcodeviewer/static/js/viewer/reader.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/octoprint/plugins/gcodeviewer/static/js/viewer/reader.js b/src/octoprint/plugins/gcodeviewer/static/js/viewer/reader.js index 507976f8a..8c7396a86 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/viewer/reader.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/viewer/reader.js @@ -154,7 +154,8 @@ GCODE.gCodeReader = (function () { this.clear(); var totalSize = reader.target.result.length; - lines = reader.target.result.split(/[\r\n]/g); + // With a regex split below as previous, memory usage is huge & takes longer. + lines = reader.target.result.replace("\r\n", "\n").split("\n"); reader.target.result = null; prepareGCode(totalSize);