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

General code generation cleanups #3248

Closed
6 of 8 tasks
mhevery opened this issue Jul 23, 2015 · 8 comments
Closed
6 of 8 tasks

General code generation cleanups #3248

mhevery opened this issue Jul 23, 2015 · 8 comments

Comments

@mhevery
Copy link
Contributor

mhevery commented Jul 23, 2015

Normalize string / No interpolation

  • Replace interpolate1 = "" "${componentName0 == null ? "" : componentName0}" "" with interpolate1 = " " + stringify(componentName0) + " "; NOTE: will require import of stringify method. I think ${} creates extra unneeded checks, so simple string concat + should be better in this case.

Inline assignments

  • take advantage of multiple assignments per line.

``` Dart``
_componentName0 = _gen.ChangeDetectionUtil.uninitialized();
_interpolate1 = _gen.ChangeDetectionUtil.uninitialized();
_directive_1_0 = _gen.ChangeDetectionUtil.uninitialized();
_directive_2_0 = _gen.ChangeDetectionUtil.uninitialized();


becomes:

``` Dart
 _componentName0 = _interpolate1 = _directive_1_0 = _directive_2_0 
       = _gen.ChangeDetectionUtil.uninitialized;
  • Also call dehydrateDirectives() from constructor so that we don't have to duplicate the code in the constructor.

Inline assignments and usages

  • inline where ever possible.
        _dispatcher.notifyOnBinding(currentProto.bindingRecord, interpolate1);
        _interpolate1 = interpolate1;

becomes

        _dispatcher.notifyOnBinding(currentProto.bindingRecord, _interpolate1 = interpolate1);

have notifyOnBinding helper

  • create viewSet in super. Notice that _dispatcher is always a View. This code is no longer abstract so we should use concrete names.
currentProto = _protos[1]
...     
change_interpolate1 = true;
_dispatcher.notifyOnBinding(currentProto.bindingRecord, interpolate1);
_interpolate1 = interpolate1;

becomes

        change_interpolate1 = viewSet(1, _interpolate1 = interpolate1);

which requires this method on superclass

  boolean viewSet(int index, dynamic value) {
    _view.notifyOnBinding(protos[index].bindingRecord, value);
    return true;
  }

looseNotIdentical

  • have loseNotIdentical which will allow us to change if (!_gen.looseIdentical(...)) to if (_gen.looseNotIdentical(...)). (its only one char, but it is everywhere)

inline context assignment

    var context = null;
    context = _context;

should be

    var context = _context;

Unused change_context

  • the code is never used in output
var change_context = false;

but is never read.

change uninitialized() method call to uninitialized static field

  • should save some chars
@mhevery mhevery added comp: dart-transformer effort2: days refactoring Issue that involves refactoring or code-cleanup labels Jul 23, 2015
@mhevery mhevery changed the title Dart code generation cleanups General code generation cleanups Jul 23, 2015
@kegluneq
Copy link

fyi, per our discussion i'm currently working on Inline assignments above

@kegluneq kegluneq assigned kevmoo and kegluneq and unassigned kevmoo Jul 24, 2015
@kegluneq
Copy link

Step 1: Determine if "Normalize string / No interpolation" provides any benefit
Step 2 already underway

kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 25, 2015
Create `NameRegistry`, responsible for understanding how names are
generated for change detector fields and variables.

Use `NameRegistry` for both JS Jit & Dart pre-generated detectors.
Making progress on angular#3248
kegluneq pushed a commit that referenced this issue Jul 27, 2015
Create `NameRegistry`, responsible for understanding how names are
generated for change detector fields and variables.

Use `NameRegistry` for both JS Jit & Dart pre-generated detectors.
Making progress on #3248
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 27, 2015
Previously, `uninitialized()` was a method, requiring a call as well as
two extra characters everywhere it was used.

Make this value a variable, saving the characters and avoiding the
method call to get its value.

This change also removes the export of `uninitialized` from
change_detect.ts, which is technically a breaking change, however
`uninitialized` is an implementation detail and nobody should be using
it in app logic. By convention, apps should not be importing from files
under `src/`.

Update to angular#3248.
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 28, 2015
Previously, `uninitialized()` was a method, requiring a call as well as
two extra characters everywhere it was used.

Make this value a variable, saving the characters and avoiding the
method call to get its value.

This change also removes the export of `uninitialized` from
change_detect.ts, which is technically a breaking change, however
`uninitialized` is an implementation detail and nobody should be using
it in app logic. By convention, apps should not be importing from files
under `src/`.

Update to angular#3248.
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 28, 2015
Create `looseNotIdentical => !looseIdentical`, which will save a lot of
unnecessary '!' characters in generated change detectors.

Update to angular#3248
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 28, 2015
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 28, 2015
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 28, 2015
Call new `(de)hydrateDirectives` methods from `(de)hydrate`. Add a null
implementation in `AbstractChangeDetector` and only override if
necessary for the specific change detector.

Update to angular#3248
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 28, 2015
Create `looseNotIdentical => !looseIdentical`, which will save a lot of
unnecessary '!' characters in generated change detectors.

Update to angular#3248
@kegluneq kegluneq added this to the alpha-34 milestone Jul 28, 2015
@yjbanov
Copy link
Contributor

yjbanov commented Jul 28, 2015

This issue proposes to optimize the size of code that we should not be generating at all. Therefore, fixing any of these will have 0 net effect on code size once we stop generating it. I'd rather we spent our time on the ultimate solution.

The ultimate solution is to move all value fields, and comparison and notification logic into common classes. Generated code should only be responsible for evaluating expressions in a typed and monomorphic manner. Here are two ways (which we can combine) for how we can do this: https://docs.google.com/document/d/1x8MmbK3bKJb5JFrz3SmLfUsWYURZhYqPux12zKm1i8k/edit#

@kegluneq
Copy link

@yjbanov , I commented on that doc but in summary I'm not confident we'll be able to implement that scheme without performance impact. Most of the ProtoRecords result in code like what you propose but not all of them and we'd need runtime checks to figure out what course of action to take.

In the mean time, this process is cutting down on code duplication, which should make any ultimate solution easier to implement.

@yjbanov yjbanov added P2: required area: performance and removed P1: urgent refactoring Issue that involves refactoring or code-cleanup labels Jul 28, 2015
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 28, 2015
Call new `(de)hydrateDirectives` methods from `(de)hydrate`. Add a null
implementation in `AbstractChangeDetector` and only override if
necessary for the specific change detector.

Update to angular#3248
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 28, 2015
Move fields common to Dynamic, Jit, and Pregen change detectors into the
`AbstractChangeDetector` superclass to save on codegen size and reduce
code duplication.

Update to angular#3248
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 29, 2015
Move fields common to Dynamic, Jit, and Pregen change detectors into the
`AbstractChangeDetector` superclass to save on codegen size and reduce
code duplication.

Update to angular#3248, closes angular#3243
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 29, 2015
Move fields common to Dynamic, Jit, and Pregen change detectors into the
`AbstractChangeDetector` superclass to save on codegen size and reduce
code duplication.

Update to angular#3248, closes angular#3243
kegluneq pushed a commit to kegluneq/angular that referenced this issue Jul 29, 2015
Move fields common to Dynamic, Jit, and Pregen change detectors into the
`AbstractChangeDetector` superclass to save on codegen size and reduce
code duplication.

Update to angular#3248, closes angular#3243
@kegluneq
Copy link

  • Double-checked, but at least for Dart, interpolation is better than + concat, so it's my intention to not complete that piece of this issue unless someone wants to discuss.
  • I'm pushing the remaining parts to the next milestone because Refactor hydrate/dehydrate/hydrated to superclass #3245 will be a bigger win and is closer to completion
    • Inline assignments and usages
    • have notifyOnBinding helper

I won't be finishing either this milestone as I'm out the next couple of days.

@kegluneq kegluneq modified the milestones: alpha-35, alpha-34 Jul 29, 2015
@kegluneq kegluneq modified the milestones: alpha-36, alpha-35 Aug 11, 2015
@kegluneq
Copy link

The remaining points here are not as urgent as supporting parts in the transformer.

@mhevery mhevery modified the milestones: alpha-36, alpha-37 Sep 1, 2015
@naomiblack naomiblack modified the milestones: alpha-37, alpha-39 Oct 4, 2015
@IgorMinar IgorMinar modified the milestone: alpha-39 Oct 5, 2015
@kegluneq
Copy link

kegluneq commented Feb 2, 2016

Change detectors & code generation in general have changed a lot - this is now obsolete.

@kegluneq kegluneq closed this as completed Feb 2, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants