You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In production, we sometime want something that runs fast. One solution is to remove parameters (type) checks performed at the start of functions. The rational being : we test it in dev mode, in prod mode there should be no bug (which is false ofc). If there are, let it explode, it's your fault. It is a little like what JS is doing when used without TS.
Therefore I suggest to use a checks-mode=unsafe option that'd remove all checks when building brython.js and brython_stdlib.js.
Checks could be identified by comments (e.g. for JS code) :
// @checks:startcheck_str(old,"replace() argument 1 ")check_str(_new,"replace() argument 2 ")// Validate instance type of 'count'if(!_b_.isinstance(count,[_b_.int,_b_.float])){throw_b_.TypeError.$factory("'"+$B.class_name(count)+"' object cannot be interpreted as an integer")}elseif(_b_.isinstance(count,_b_.float)){throw_b_.TypeError.$factory("integer argument expected, got float")}// @checks:end
Cordially,
The text was updated successfully, but these errors were encountered:
// by default :assert={isNumber: (i)=>{if(!Number.isInteger(i))thrownewError('nok')}};// if check-mode = unsafe :assert={isNumber: (_i)=>{}};
Using a function will help factorizing your code making it :
a little faster (but not much).
more readable.
easier to maintain.
reduce your code size (so lesser download and parsing time).
Using an empty assert :
increase runtime execution (checking is 28% slower).
allows to be enabled/disabled during runtime.
still takes some code space (but less as this is always the same small function to call).
still takes some performances (strangely enough doing nothing is 37% slower in my tests - stupid browser runtime code optimizations xD).
could enable to remove such lines from the code through a command-line tool (but better not doing it - I think the gain wouldn't be that great, and that'd be a little troublesome).
denis-migdal
changed the title
Option "checks-mode=unsafe" to optimize runtime
Factorize assertions + Option "checks-mode=unsafe" to optimize runtime
Oct 11, 2023
Hi,
In production, we sometime want something that runs fast. One solution is to remove parameters (type) checks performed at the start of functions. The rational being : we test it in dev mode, in prod mode there should be no bug (which is false ofc). If there are, let it explode, it's your fault. It is a little like what JS is doing when used without TS.
Therefore I suggest to use a
checks-mode=unsafe
option that'd remove all checks when buildingbrython.js
andbrython_stdlib.js
.Checks could be identified by comments (e.g. for JS code) :
Cordially,
The text was updated successfully, but these errors were encountered: