diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-06-25 22:25:39 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-06-25 22:25:39 +0800 |
commit | 24f2fddb6f70576bc101021637014af1bdbb68b6 (patch) | |
tree | c65d9c01a6d475e4737fc54ca67ae12e3c7d8fe3 | |
parent | b1bc366e52cf719f0e3f01719fd787e7873baf84 (diff) | |
download | SoopyV2-24f2fddb6f70576bc101021637014af1bdbb68b6.tar.gz SoopyV2-24f2fddb6f70576bc101021637014af1bdbb68b6.tar.bz2 SoopyV2-24f2fddb6f70576bc101021637014af1bdbb68b6.zip |
+ finish performance thing (mostly)
+ optimisations for slayer hide 0hp nametags
-rw-r--r-- | featureClass/featureManager.js | 119 | ||||
-rw-r--r-- | features/cosmetics/index.js | 2 | ||||
-rw-r--r-- | features/globalSettings/index.js | 9 | ||||
-rw-r--r-- | features/hud/index.js | 4 | ||||
-rw-r--r-- | features/slayers/index.js | 16 | ||||
-rw-r--r-- | features/soopyGui/index.js | 2 |
6 files changed, 99 insertions, 53 deletions
diff --git a/featureClass/featureManager.js b/featureClass/featureManager.js index 5200b57..ba86658 100644 --- a/featureClass/featureManager.js +++ b/featureClass/featureManager.js @@ -17,14 +17,18 @@ const StrongCachingModuleScriptProviderClass = Java.type("org.mozilla.javascript let StrongCachingModuleScriptProvider = new StrongCachingModuleScriptProviderClass(UrlModuleSourceProviderInstance) let CTRequire = new JSLoader.CTRequire(StrongCachingModuleScriptProvider) +const System = Java.type("java.lang.System") + let loadedModules = new Set() -let shouldRequireNoCache = true +let shouldRequireForceNoCache = true function RequireNoCache(place) { - if (!logger.isDev && shouldRequireNoCache) return require(place) - if (!loadedModules.has(place)) { - loadedModules.add(place) - return require(place) //performance optimisation + if (!shouldRequireForceNoCache) { + if (!logger.isDev) return require(place) + if (!loadedModules.has(place)) { + loadedModules.add(place) + return require(place) //performance optimisation + } } StrongCachingModuleScriptProvider = new StrongCachingModuleScriptProviderClass(UrlModuleSourceProviderInstance) @@ -66,6 +70,7 @@ class FeatureManager { //PERFORMANCE RECORDING this.recordingPerformanceUsage = false this.performanceUsage = {} //{<moduleName>: {<event>: {time: 0, count: 0}}} + this.flameGraphData = [] this.longEventTime = 20 @@ -182,17 +187,25 @@ class FeatureManager { }, this) } + getId() { + return "FeatureManager" + } + loadPerformanceData() { new Thread(() => { ChatLib.chat(this.messagePrefix + "Recording performance impact, this will take around 50 seconds to complete!") - shouldRequireNoCache = false + shouldRequireForceNoCache = true let eventLagData = this.loadEventLag() ChatLib.chat(this.messagePrefix + "ETA: 40s") + this.perfTrackingFeatures = true this.unloadSoopy() this.loadSoopy() + Thread.sleep(1000) let eventLagDataFull = this.loadEventLag() + this.perfTrackingFeatures = false this.unloadSoopy() this.loadSoopy() + Thread.sleep(1000) ChatLib.chat(this.messagePrefix + "ETA: 25s") let forgeLagData = this.loadForgeRenderLag() ChatLib.chat(this.messagePrefix + "ETA: 15s") @@ -205,10 +218,14 @@ class FeatureManager { soopyLagData } - shouldRequireNoCache = true + shouldRequireForceNoCache = false let url = this.reportLagData(lagData) ChatLib.chat(this.messagePrefix + "Done!") new TextComponent(this.messagePrefix + "See the report at " + url).setClick("open_url", url).setHover("show_text", "Click to open the report.").chat() + + + this.performanceUsage = {} + this.flameGraphData = [] }).start() } @@ -280,6 +297,7 @@ class FeatureManager { loadEventLag() { this.recordingPerformanceUsage = true this.performanceUsage = {} + this.flameGraphData = [] // ChatLib.chat(this.messagePrefix + "Recording Event Lag...") Thread.sleep(10000) @@ -316,7 +334,7 @@ class FeatureManager { // }) // ChatLib.chat("&eTotal: &7" + totalMsGlobal.toFixed(2) + "ms") - return this.performanceUsage + return { performanceUsage: this.performanceUsage, flameGraphData: this.flameGraphData } } loadFeatureSettings() { @@ -401,14 +419,14 @@ class FeatureManager { try { for (Event of Object.values(this.events[event])) { if (Event.context.enabled) { - if (this.recordingPerformanceUsage) this.startRecordingPerformance(Event.context.constructor.name, event) + if (this.recordingPerformanceUsage) this.startRecordingPerformance(Event.context.getId(), event) let start = Date.now() Event.func.call(Event.context, ...args) let time = Date.now() - start if (time > this.longEventTime) { - logger.logMessage("Long event triggered [" + time + "ms] (" + Event.context.constructor.name + "/" + event + ")", 3) + logger.logMessage("Long event triggered [" + time + "ms] (" + Event.context.getId() + "/" + event + ")", 3) } - if (this.recordingPerformanceUsage) this.stopRecordingPerformance(Event.context.constructor.name, event) + if (this.recordingPerformanceUsage) this.stopRecordingPerformance(Event.context.getId(), event) } } } catch (e) { @@ -424,14 +442,14 @@ class FeatureManager { try { for (Event of Object.values(this.soopyEventHandlers[event])) { if (Event.context.enabled) { - if (this.recordingPerformanceUsage) this.startRecordingPerformance(Event.context.constructor.name, event) + if (this.recordingPerformanceUsage) this.startRecordingPerformance(Event.context.getId(), event) let start = Date.now() Event.func.call(Event.context, ...args) let time = Date.now() - start if (time > this.longEventTime) { - logger.logMessage("Long event triggered [" + time + "ms] (" + Event.context.constructor.name + "/" + event + ")", 3) + logger.logMessage("Long event triggered [" + time + "ms] (" + Event.context.getId() + "/" + event + ")", 3) } - if (this.recordingPerformanceUsage) this.stopRecordingPerformance(Event.context.constructor.name, event) + if (this.recordingPerformanceUsage) this.stopRecordingPerformance(Event.context.getId(), event) } } } catch (e) { @@ -534,14 +552,14 @@ class FeatureManager { trigger: register(type, (...args) => { try { if (context.enabled) { - if (this.recordingPerformanceUsage) this.startRecordingPerformance(context.constructor.name, type) + if (this.recordingPerformanceUsage) this.startRecordingPerformance(context.getId(), type) let start = Date.now() func.call(context, ...(args || [])) let time = Date.now() - start if (time > this.longEventTime) { - logger.logMessage("Long event triggered [" + time + "ms] (" + context.constructor.name + "/" + type + ")", 3) + logger.logMessage("Long event triggered [" + time + "ms] (" + context.getId() + "/" + type + ")", 3) } - if (this.recordingPerformanceUsage) this.stopRecordingPerformance(context.constructor.name, type) + if (this.recordingPerformanceUsage) this.stopRecordingPerformance(context.getId(), type) } } catch (e) { logger.logMessage("Error in " + type + " event: " + JSON.stringify(e, undefined, 2), 2) @@ -565,14 +583,14 @@ class FeatureManager { trigger: registerForgeBase(event, priority, (...args) => { try { if (context.enabled) { - if (this.recordingPerformanceUsage) this.startRecordingPerformance(context.constructor.name, event.class.name) + if (this.recordingPerformanceUsage) this.startRecordingPerformance(context.getId(), event.class.name) let start = Date.now() func.call(context, ...(args || [])) let time = Date.now() - start if (time > this.longEventTime) { - logger.logMessage("Long (forge) event triggered (" + context.constructor.name + "/" + event.class.toString() + ")", 3) + logger.logMessage("Long (forge) event triggered (" + context.getId() + "/" + event.class.toString() + ")", 3) } - if (this.recordingPerformanceUsage) this.stopRecordingPerformance(context.constructor.name, event.class.name) + if (this.recordingPerformanceUsage) this.stopRecordingPerformance(context.getId(), event.class.name) } } catch (e) { logger.logMessage("Error in " + event.class.toString() + " (forge) event: " + JSON.stringify(e, undefined, 2), 2) @@ -649,32 +667,57 @@ class FeatureManager { if (!this.perfTrackingFeatures) return Object.getOwnPropertyNames(Object.getPrototypeOf(feature)).forEach(key => { - ChatLib.chat(key + " " + typeof (feature[key])) if (typeof (feature[key]) === "function") { let fun = feature[key].bind(feature) - feature[key] = () => { - if (!this.recordingPerformanceUsage) { - fun() + feature[key] = (...args) => { + if (!this.recordingPerformanceUsage || Thread.currentThread().getId() !== 1 || !this.perfTrackingFeatures) { + let err = undefined + try { + args ? fun(...args) : fun() + } catch (e) { + err = e + } + if (err) throw err return } let pushedId = false + let start = this.getExactTime() if (this.stack.length === 0) { - this.stack.push(featureId) + this.stack.push([featureId, 0]) + // this.flameGraphData.push({ isEnter: true, thing: featureId, time: start }) pushedId = true } + this.stack.push([featureId + "." + key, 0]) + + // this.flameGraphData.push({ isEnter: true, thing: featureId + "." + key, time: start }) + let err = undefined + try { + args ? fun(...args) : fun() + } catch (e) { + err = e + } + let nowTime = this.getExactTime() + let time = (nowTime - start) - this.stack[this.stack.length - 1][1] + + this.stack[this.stack.length - 2][1] += nowTime - start + + if (!this.performanceUsage[featureId]) this.performanceUsage[featureId] = {} + if (!this.performanceUsage[featureId].functions) this.performanceUsage[featureId].functions = {} + if (!this.performanceUsage[featureId].functions[key]) this.performanceUsage[featureId].functions[key] = { time: 0, count: 0 } + this.performanceUsage[featureId].functions[key].count++ + this.performanceUsage[featureId].functions[key].time += nowTime - start + + this.flameGraphData.push(this.stack.map(a => a[0]).join(";") + " " + (time)) + this.stack.pop()[1] + if (pushedId) { + let time = (nowTime - start) - this.stack[this.stack.length - 1][1] + this.flameGraphData.push(this.stack.map(a => a[0]).join(";") + " " + (time)) + this.stack.pop() + } - this.stack.push(featureId + "." + key) - - let start = this.getExactTime() - fun() - let time = this.getExactTime() - start - - this.performanceUsage - - this.stack.pop() - if (pushedId) this.stack.pop() + if (err) throw err } } }) @@ -771,10 +814,8 @@ class FeatureManager { } getExactTime() { - let instant = Instant.now() - return (instant.getEpochSecond() + (instant.getNano() / 1000000000)) * 1000; + return System.nanoTime() / 1000000 } - startRecordingPerformance(feature, event) { if (!this.recordingPerformanceUsage) return @@ -790,7 +831,7 @@ class FeatureManager { let time = this.getExactTime() - this.performanceUsage[feature][event].time += time - this.performanceUsage[feature][event].startTime + this.performanceUsage[feature][event].time += (time - this.performanceUsage[feature][event].startTime) this.performanceUsage[feature][event].count++ } } diff --git a/features/cosmetics/index.js b/features/cosmetics/index.js index ffe25dc..6c832ef 100644 --- a/features/cosmetics/index.js +++ b/features/cosmetics/index.js @@ -194,7 +194,7 @@ class Cosmetics extends Feature { } shouldPlayerHaveCosmetic(player, cosmetic) { - if (!!this.cosmeticsData[player.getUUID().toString().replace(/-/g, "")]?.[cosmetic]) { + if (this.getPlayerCosmeticSettings(player, cosmetic)) { if (!this.getPlayerCosmeticSettings(player, cosmetic).enabled) return false return true } diff --git a/features/globalSettings/index.js b/features/globalSettings/index.js index 1e4bba1..bf918f1 100644 --- a/features/globalSettings/index.js +++ b/features/globalSettings/index.js @@ -46,6 +46,8 @@ class GlobalSettings extends Feature { this.reportErrorsSetting = new ToggleSetting("Send module errors to soopy server", "This will allow me to more effectivly fix them", false, "privacy_send_errors", this) + this.hideFallingBlocks = new ToggleSetting("Hide falling blocks", "NOTE: this may cause more lag because of render entity event", false, "hide_falling_sand", this) + this.privacySettings = [this.reportErrorsSetting] this.firstLoadPageData = JSON.parse(FileLib.read("soopyAddonsData", "soopyv2firstloaddata.json") || "{}") || {} @@ -55,6 +57,13 @@ class GlobalSettings extends Feature { soopyV2Server.reportErrorsSetting = this.reportErrorsSetting this.registerChat("&aYour new API key is &r&b${key}&r", this.newKey) + const EntityFallingBlock = Java.type("net.minecraft.entity.item.EntityFallingBlock"); + + this.registerEvent('renderEntity', (entity, posVec, partialTicks, event) => { + if (entity.getEntity() instanceof EntityFallingBlock) { + cancel(event); + } + }).registeredWhen(() => this.hideFallingBlocks.getValue()) this.ranFirstLoadThing = false diff --git a/features/hud/index.js b/features/hud/index.js index a889345..6f23b24 100644 --- a/features/hud/index.js +++ b/features/hud/index.js @@ -14,9 +14,6 @@ import { numberWithCommas } from "../../utils/numberUtils.js"; const ProcessBuilder = Java.type("java.lang.ProcessBuilder") const Scanner = Java.type("java.util.Scanner") -const Base64 = Java.type("java.util.Base64") -const CompressedStreamTools = Java.type("net.minecraft.nbt.CompressedStreamTools") -const ByteArrayInputStream = Java.type("java.io.ByteArrayInputStream") class Hud extends Feature { constructor() { @@ -405,6 +402,7 @@ class Hud extends Feature { let time = instant.getEpochSecond() + (instant.getNano() / 1000000000); let thisframeTime = time - this.lastFrame + // console.log(thisframeTime * 1000) if (thisframeTime > this.slowestFrameTime) { this.slowestFrameTime = thisframeTime diff --git a/features/slayers/index.js b/features/slayers/index.js index 590970a..348f7c4 100644 --- a/features/slayers/index.js +++ b/features/slayers/index.js @@ -305,21 +305,19 @@ class Slayers extends Feature { } if (this.BoxAroundMiniboss.getValue() || this.betterHideDeadEntity.getValue()) { - World.getAllEntitiesOfType(net.minecraft.entity.item.EntityArmorStand).forEach(name => { - let MobName = `${name.getName().removeFormatting().split(" ")[0]} ${name.getName().removeFormatting().split(" ")[1]}` + let entitys = World.getAllEntitiesOfType(net.minecraft.entity.item.EntityArmorStand) + for (let name of entitys) { + let nameSplit = name.getName().removeFormatting().split(" ") + let MobName = nameSplit[0] + " " + nameSplit[1] if (this.BoxAroundMiniboss.getValue() && !this.bossSpawnedMessage && this.Miniboss[this.lastSlayerType]?.has(MobName) && !this.minibossEntity.map(a => a[0].getUUID().toString()).includes(name.getUUID().toString())) { - this.minibossEntity.push([new Entity(name.getEntity()), this.lastSlayerType]); + this.minibossEntity.push([name, this.lastSlayerType]); } if (this.betterHideDeadEntity.getValue()) { - if (name.getName().removeFormatting().split(" ")[name.getName().removeFormatting().split(" ").length - 1] === "0❤" || - ( - name.getName().removeFormatting().split(" ")[name.getName().removeFormatting().split(" ").length - 1].split("/")[0] === "0" - && name.getName().removeFormatting().includes("❤")) - ) { + if (nameSplit[nameSplit.length - 1][0] === "0" && nameSplit[nameSplit.length - 1].endsWith("❤")) { name.getEntity()[m.setAlwaysRenderNameTag](false) } } - }); + } } } diff --git a/features/soopyGui/index.js b/features/soopyGui/index.js index 32ac1a7..1d4bc45 100644 --- a/features/soopyGui/index.js +++ b/features/soopyGui/index.js @@ -103,7 +103,7 @@ class SoopyGui extends Feature { this.buttonListElm.children = [] - this.getPages().forEach((p, i) => { + if (this.getPages()) this.getPages().forEach((p, i) => { let settingsButton = new ButtonWithArrow().setText("§0" + p.name).setLocation(0, 0.225 * i, 1, 0.2) settingsButton.addEvent(new SoopyMouseClickEvent().setHandler(() => { this.clickedOpen(p) })) this.buttonListElm.addChild(settingsButton) |