From e9dbeb7760d59cdb0369052d558b025ea9485cb0 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alex.rose@rcsb.org>
Date: Thu, 7 Mar 2019 15:47:18 -0800
Subject: [PATCH] ignore user timings for production build

---
 src/mol-task/util/user-timing.ts | 14 ++++++++++----
 webpack.config.js                |  2 --
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/mol-task/util/user-timing.ts b/src/mol-task/util/user-timing.ts
index fc64b57ab..a4e3b7e33 100644
--- a/src/mol-task/util/user-timing.ts
+++ b/src/mol-task/util/user-timing.ts
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -7,17 +7,23 @@
 import { Task } from '../task'
 
 const hasPerformance = typeof performance !== 'undefined'
+/**
+ * on node `process.env.NODE_ENV` is available, in webpack build it is automatically set
+ * by the DefinePlugin to the webpack `mode` value
+ */
+const productionMode = process.env.NODE_ENV === 'production'
+const timingEnabled = hasPerformance && !productionMode
 
 export namespace UserTiming {
     function startMarkName(task: Task<any>) { return `startTask${task.id}` }
     function endMarkName(task: Task<any>) { return `endTask${task.id}` }
     export function markStart(task: Task<any>) {
-        if (hasPerformance) performance.mark(startMarkName(task))
+        if (timingEnabled) performance.mark(startMarkName(task))
     }
     export function markEnd(task: Task<any>) {
-        if (hasPerformance) performance.mark(endMarkName(task))
+        if (timingEnabled) performance.mark(endMarkName(task))
     }
     export function measure(task: Task<any>) {
-        if (hasPerformance) performance.measure(task.name, startMarkName(task), endMarkName(task))
+        if (timingEnabled) performance.measure(`✳️ ${task.name}`, startMarkName(task), endMarkName(task))
     }
 }
\ No newline at end of file
diff --git a/webpack.config.js b/webpack.config.js
index 3c8b6502a..0298bc8f7 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -49,8 +49,6 @@ const sharedConfig = {
         }),
         new webpack.DefinePlugin({
             __PLUGIN_VERSION_TIMESTAMP__: webpack.DefinePlugin.runtimeValue(() => `${new Date().valueOf()}`, true),
-            // include this for production version of React
-            // 'process.env.NODE_ENV': JSON.stringify('production')
         }),
         new MiniCssExtractPlugin({ filename: 'app.css' })
     ],
-- 
GitLab