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

Optimize Ti.API.debug behaviour #13837

Open
1 task done
m1ga opened this issue May 15, 2023 · 2 comments · May be fixed by #13838
Open
1 task done

Optimize Ti.API.debug behaviour #13837

m1ga opened this issue May 15, 2023 · 2 comments · May be fixed by #13838
Labels
feature needs triage This issue hasn't been reviewed by maintainers

Comments

@m1ga
Copy link
Contributor

m1ga commented May 15, 2023

I have searched and made sure there are no existing issues for the issue I am filing

  • I have searched the existing issues

Description

Currently a store build hides Ti.API.debug output but it still is in the code and gets executed

let i = 0;
let c = 0;
Ti.API.info(`-------------INFO: ${++i}`);
console.log(`-------------LOG: ${++c}`);

Ti.API.debug(`-------------DEBUG: ${++i}`);
console.debug(`-------------LOG DEBUG: ${++c}`);

Ti.API.info(`-------------INFO: ${++i}`);
console.log(`-------------LOG: ${++c}`);

will output

TiAPI   :  -------------INFO: 1
TiAPI   :  -------------LOG: 1
TiAPI   :  -------------INFO: 3
TiAPI   :  -------------LOG: 3

in a store build. While the log is gone it still calls the line.

Having heavy JSON.stringify parts in there could potentially slow down the app without doing anything.

Solution

In the old Appc blog post about babel modules it will talk about babel-plugin-transform-remove-console that can be used to remove console.debug lines from the code. There is already babel-plugin-transform-titanium to optimize code for e.g. OS_ANDROID calls.
So perhaps it would be interesting to add something like the minify flag to https://github.com/tidev/node-titanium-sdk/blob/master/lib/jsanalyze.js to completely remove .debug logs from a store build instead of not just outputting it.

Alternatives

  • overwrite the debug function in your app and use a local one
  • use the babel module yourself

Platforms

Android & iOS

@m1ga m1ga added feature needs triage This issue hasn't been reviewed by maintainers labels May 15, 2023
@m1ga
Copy link
Contributor Author

m1ga commented May 15, 2023

Did some tests already and

CallExpression(path, state) {
	const callee = path.get("callee");
	if (!callee.isMemberExpression()) return;
	if (path.get('callee').matchesPattern('Ti.API.debug')) {
		path.replaceWith(types.nullLiteral());
	} else if (path.get('callee').matchesPattern('Titanium.API.debug')) {
		path.replaceWith(types.nullLiteral());
	}
},

in https://github.com/tidev/node-titanium-sdk/blob/master/lib/babel-plugins/ti-api.js#L92 will already NULL all debug calls.

It can be done as a different babel-plugin file (remove-debug-lines) and load it

options.plugins.push(require.resolve('./babel-plugins/remove-debug-lines'));

in the minify block https://github.com/tidev/node-titanium-sdk/blob/master/lib/jsanalyze.js#L152 since that is called during a production run.

@m1ga
Copy link
Contributor Author

m1ga commented May 15, 2023

SDK PR: #13838
node-titanium-sdk PR: tidev/node-titanium-sdk#651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature needs triage This issue hasn't been reviewed by maintainers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant