Skip to content

Point Observation #267

@typesupply

Description

@typesupply

Almost all objects in defcon participate in the notification system (which is based on the observer pattern). Points are the main exception and it has been a problem for years. Perhaps someone could solve this.

The Problem

When you make a change to a Point, nothing is informed about the change to the font. For example:

contour = glyph[0]
point = contour[0]
point.x = 100

In the current version of the Point object, the contour will not receive any notification that point has changed. This is fine as long as the high-level code is diligent about notifying contour on it's own. In fact, if you call contour.move, that's what Contour does internally. However, if the high-level code does not do the notification work, things get out of sync. This sucks because defcon has a "it just works" model and this doesn't just work.

Some History

When I wrote defcon, Points were just like every object in that they tied into the overall notification center. Any change made to a Point would trigger a Point.Changed notification through the shared contour-glyph-font notification system. As best as I can recall, this created some significant problems due to the number of points in a font:

  1. Loading a UFO was slow because each Point object in the GLIF being read had to go through the full process of joining the notification system.
  2. Moving the contents of a glyph (as in the case of setting a left margin) would cause sum([len(contour) for contour in glyph]) Point.Changed notifications to be posted and this was a serious performance drag.
  3. A substantial amount of memory was required for all of the points in the notification system.

I removed Points from the notification system because I couldn't find a way to solve it. It has bugged (no pun intended) me since.

Possible Solutions

A lot has changed since the early days of defcon. We have better control for holding and muting notifications. Many parts of defcon have been optimized. Hardware has improved.

These are the ideas that I've had for trying to solve the problem:

  1. Put Points back in the notification system and see what happens. Maybe hardware improvements have improved in the last 13 years.
  2. Create a weak reference between points and their parent contours and use that to notify the contour that a point changed.
  3. Create a separate, very light notification system just for communication between points and a contour rather than using the notification dispatcher that is shared across a font. (This shared dispatcher itself is an optimization from the early days of defcon. Creating many dispatchers was expensive.)
  4. Find an observer pattern replacement that scales well.
  5. ??????????

I have no idea if these will work and I don't have time to take on the issue myself. If someone out there wants to give it a shot, please do. Test it by throwing some big UFOs at it and moving lots of points around. I'll stay subscribed to this issue if you want to discuss.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions