nahkd123 / inking

Java to OpenTabletDriver (OTD) bridge.
MIT License
0 stars 0 forks source link

inking-manager: Redesign filtering system #10

Closed nahkd123 closed 7 months ago

nahkd123 commented 7 months ago

Current system is prone to high memory allocation. I believe it's because of allocation of Consumer to pass packets generated from current filter to next filter for every packet emitted. Combine that with my 240Hz tablet and it would fill up the memory, causing GC to trigger more frequent.

The new Packet Filter interface will be something like this:

public interface PacketFilter {
    public void initialize(FilterHost host, Consumer<Packet> pusher);
    public void onPacket(Packet packet);
    public Codec<? extends PacketFilter> getCodec();
}

Additionally, a new AbstractPacketFilter will be added to include additional methods:

public interface IAbstractPacketFilter extends PacketFilter {
    @Override
    default void initialize(FilterHost host, Consumer<Packet> pusher) {} // implemented in abstract class

    public void push(Packet packet);
    public FilterHost getHost();
}
nahkd123 commented 7 months ago

Resolved in https://github.com/nahkd123/inking/commit/d6bf0d0fda23f3f12dc8e157d7b9e972651b03ba